Skip to content

DO NOT MERGE YET: Compatibility to Socket.io 1.x #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/acknowledgements/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ app.http().io()

// Setup the ready route.
app.io.route('ready', function(req) {
console.log("me",this);
req.io.respond({
success: 'here is your acknowledegment for the ready event'
})
Expand Down
10 changes: 6 additions & 4 deletions examples/acknowledgements/client.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<script src="/socket.io/socket.io.js"></script>
<script>
io = io.connect()
var client = io()

// Emit ready event, and wait for acknowledgement.
io.emit('ready', {hey: 'server'}, function(data) {
alert(data.success)
})
client.on("connect", function(){
io.emit('ready', {hey: 'server'}, function(data) {
alert(data.success)
});
});
</script>
43 changes: 19 additions & 24 deletions lib/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ express.application.io = (options) ->
_.defaults options, defaultOptions
@io = io.listen @server, options
@io.router = new Object
@io.middleware = []
@io.route = (route, next, options) ->
if options?.trigger is true
if route.indexOf ':' is -1
Expand All @@ -56,13 +55,14 @@ express.application.io = (options) ->
else
for key, value of next
@router["#{route}:#{key}"] = value
@io.configure => @io.set 'authorization', (data, next) =>

@io.use => (data, next) =>
unless sessionConfig.store?
return async.forEachSeries @io.middleware, (callback, next) ->
callback(data, next)
, (error) ->
return next error if error?
next null, true
next()
cookieParser = cookieParser()
cookieParser data, null, (error) ->
return next error if error?
Expand All @@ -78,17 +78,13 @@ express.application.io = (options) ->
sessionConfig.store.get sessionId, (error, session) ->
return next error if error?
data.session = new expressSession.Session data, session
next null, true

next()
sessionId = cookieParserUtils.signedCookies rawCookie, sessionConfig.secret
data.sessionID = sessionId
sessionConfig.store.get sessionId, (error, session) ->
return next error if error?
data.session = new expressSession.Session data, session
next null, true

@io.use = (callback) =>
@io.middleware.push callback
next()

@io.sockets.on 'connection', (socket) =>
initRoutes socket, @io
Expand All @@ -98,13 +94,12 @@ express.application.io = (options) ->
@io.sockets.emit.apply @io.sockets, args

@io.room = (room) =>
new RoomIO(room, @io.sockets)

layer = new expressLayer('',
sensitive: undefined
strict: undefined
end: false
, (request, response, next) =>
new RoomIO(room, @io.sockets)

eioInitialize = ->
return (request, response, next) =>
# Since we are not in a this = app context at this moment...
self = request.app
request.io =
route: (route) =>
ioRequest = new Object
Expand All @@ -116,16 +111,11 @@ express.application.io = (options) ->
args = Array.prototype.slice.call arguments, 0
response.json.apply response, args
route: (route) =>
@io.route route, ioRequest, trigger: true
self.io.route route, ioRequest, trigger: true
data: request.body
@io.route route, ioRequest, trigger: true
broadcast: @io.broadcast
broadcast: self.io.broadcast
next()
)

@_router.stack.push layer

return this

listen = express.application.listen
express.application.listen = ->
Expand All @@ -134,7 +124,11 @@ express.application.listen = ->
@server.listen.apply @server, args
else
listen.apply this, args


lazyrouter = express.application.lazyrouter
express.application.lazyrouter = ->
lazyrouter.apply this
@_router.use eioInitialize()

initRoutes = (socket, io) ->
setRoute = (key, callback) ->
Expand All @@ -158,6 +152,7 @@ initRoutes = (socket, io) ->
request.io.respond = respond
request.io.respond ?= ->
callback request
console.log io.router
for key, value of io.router
setRoute(key, value)

Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
}
],
"dependencies": {
"async": "0.1.22",
"coffee-script": "1.4.0",
"cookie-parser": "^1.1.0",
"express": "^4.4.0",
"express-session": "^1.2.1",
"socket.io": "~0.9.16",
"underscore": "1.4.3"
"async": "0.9.0",
"coffee-script": "1.9.1",
"cookie-parser": "^1.3.4",
"express": "^4.12.3",
"express-session": "^1.11.1",
"socket.io": "~1.3.5",
"underscore": "1.8.3"
},
"devDependencies": {
"request": "*",
Expand Down