Skip to content

Commit

Permalink
重构, bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ericwangqing committed Sep 23, 2013
1 parent fe28ed7 commit 5e89215
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
32 changes: 17 additions & 15 deletions src/channels/locations-channel.ls
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ join-locations-rooms = !(socket, locations)->

join-inexsitence-locations-rooms =!(socket, inexistence-locations-urls)->
for url in inexistence-locations-urls
socket.join get-room url
socket.join room = get-room url
debug "socket: #{socket.id} join #{room}"

get-room = (inexistence-location-url)->
Expand All @@ -72,7 +72,7 @@ replace-uids-with-brief-users = !(interesting-points-summaries-map, brief-users-

change-url-room-to-location-room = !(location-channel, url, location)->
debug "------ in: 'change-url-room-to-location-room' ---------"
for client in location-channel.clients url
for client in location-channel.clients get-room url
debug "client socket: #{client.id} join #{location._id}"
client.leave get-room url
client.join location._id
Expand All @@ -84,6 +84,21 @@ get-push-location-updated-message = (data)->

module.exports =
init: !(io)->
# ----- 以下响应服务端business层的请求 ---------------- #
event-bus.on 'locations-channel:ask-location-internality', !(data)->
if io.sockets.sockets[data.session-id]
debug "------ in: 'locations-channel:ask-location-internality' ---------"
debug "------ emit: 'ask-location-internality' --------- socket: ", io.sockets.sockets[data.session-id].id
io.of('/locations').sockets[data.session-id].emit 'ask-location-internality', data


event-bus.on 'locations-channel:location-updated', !(data)~>
if io.sockets.sockets[data.session-id]
debug "------ in: 'locations-channel:location-updated' --------- socket: ", io.sockets.sockets[data.session-id].id
change-url-room-to-location-room io.of('/locations'), data.url, data.location
debug "------ broadcast: 'push-location-updated' ---------"
io.of('/locations').sockets[data.session-id].broadcast.to(data.location._id).emit 'push-location-updated', get-push-location-updated-message data

channel-initial-wrapper.server-channel-initial-wrapper {
channel: io.of('/locations')

Expand All @@ -101,19 +116,6 @@ module.exports =
if (data.is-internal)
locations-manager.update-location-internality data.lid, true

# ----- 以下响应服务端business层的请求 ---------------- #
event-bus.on 'locations-channel:ask-location-internality', !(data)->
debug "------ in: 'locations-channel:ask-location-internality' --------- socket: ", socket.id
debug "------ emit: 'ask-location-internality' ---------"
socket.emit 'ask-location-internality', data if socket.id is data.session-id


event-bus.on 'locations-channel:location-updated', !(data)~>
debug "------ in: 'locations-channel:location-updated' --------- socket: ", socket.id
change-url-room-to-location-room @channel, data.url, data.location
debug "------ broadcast: 'push-location-updated' ---------"
socket.broadcast.to(data.location.lid).emit 'push-location-updated', get-push-location-updated-message data if socket.id is data.session-id

# socket.on 'leave-location'

callback!
Expand Down
5 changes: 4 additions & 1 deletion test/helpers/test-create-a-new-ip-on-a-new-url-helper.ls
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require! ['./utils', './socket-helper']
debug = require('debug')('at-plus')
test-url = utils.load-fixture 'request-create-a-new-ip-on-a-new-url' .within-location.url

open-client-without-testing-helper = !(callback)->
open-client null, callback
Expand All @@ -22,7 +23,9 @@ open-client = !(testing-helper-channel-config, callback)->
waiter = new utils.All-done-waiter! # 用以保存各个频道的channels,在所有回调结束后才可用。
channels-configs =
default-channel: {}
locations-channel: {}
locations-channel: options: request-initial-data: locations:
type: "web"
urls: [test-url]
interesting-points-channel: business-handler-register: !(socket, data)->
socket-helper.Sockets-distroyer.get!.add-socket socket # 为了在每个测试结束,关闭服务端的socket,以便隔离各个测例。
waiter.set-done ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ should-db-include-a-new-interesting-point = !(old-amount, callback)->
should-db-include-the-requested-new-ip = !(new-ip, callback)->
debug "new-ip.title: ", new-ip.title
(ips) <-! query-collection 'interesting-points', {'title': new-ip.title}
if ips.length > 1
debug "ips: ", ips
ips.length.should.eql 1
callback!

Expand Down

0 comments on commit 5e89215

Please sign in to comment.