Skip to content

Instantly share code, notes, and snippets.

@vird
Created September 9, 2014 15:09
Show Gist options
  • Save vird/881ae3552e0c9f93a32e to your computer and use it in GitHub Desktop.
Save vird/881ae3552e0c9f93a32e to your computer and use it in GitHub Desktop.
seems primus+engine.io can't utf8
4{"switch":"pongРУССКИЙ"}
<html ng-app="root">
<head>
<title>Template socketio angular</title>
<script src="/primus/primus.js"></script>
<script>
var websocket = new Primus(location.origin);
websocket.on('data', function(data) {
console.log(data);
});
setTimeout(function(){
websocket.write({switch:"ping"});
},5000);
</script>
</head>
<body>
<div>
</div>
</body>
</html>
process.on 'uncaughtException', (err) ->
console.log err
console.log err.stack
express = require 'express'
http = require 'http'
ect = require 'ect'
Primus = require 'primus'
body_parser = require 'body-parser'
compression = require 'compression'
# ###################################################################################################
ectRenderer = ect
root : 'views'
# ###################################################################################################
app = express()
app.use compression()
app.use body_parser.urlencoded extended: true
app.set 'view engine', 'ect'
app.engine 'ect', ectRenderer.render
app.get '/', (req, res, next)->
res.render 'index.ect'
server = http.createServer(app).listen(1337)
primus = new Primus server,
transformer : 'engine.io'
# transformer : 'websockets'
parser : 'JSON'
primus.on 'connection', (socket)->
socket.on 'data', (data)->
switch data.switch
when "ping"
socket.write
'switch':'pongРУССКИЙ'
console.log "started"
npm install express ext primus ws engine.io body-parser compression
mkdir views
mv index.ect views/index.ect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment