replaced NotificationCenter with Nc

This commit is contained in:
logsol 2014-03-01 11:07:23 +01:00
parent da913c4709
commit 672a46efa8
35 changed files with 160 additions and 161 deletions

View file

@ -3,7 +3,7 @@ define([
"Lib/Utilities/Protocol/Helper"
],
function (NotificationCenter, ProtocolHelper) {
function (Nc, ProtocolHelper) {
function Api(coordinator) {
this.coordinator = coordinator;

View file

@ -5,7 +5,7 @@ define([
"Lib/Utilities/NotificationCenter"
],
function (User, Channel, PipeToChannel, NotificationCenter) {
function (User, Channel, PipeToChannel, Nc) {
function Coordinator () {
this.channelPipes = {};
@ -46,14 +46,14 @@ function (User, Channel, PipeToChannel, NotificationCenter) {
//channel.addUser(user);
//user.setChannel(channel);
NotificationCenter.trigger('user/joined', user);
Nc.trigger('user/joined', user);
delete this.lobbyUsers[user.id];
}
Coordinator.prototype.removeUser = function (user) {
NotificationCenter.trigger('user/left', user);
Nc.trigger('user/left', user);
//NotificationCenter.off('channel/' + user.channel.channelName + '/user/' + user.id);
delete this.lobbyUsers[user.id];
@ -65,14 +65,14 @@ function (User, Channel, PipeToChannel, NotificationCenter) {
this.channelPipes[channelName] = channelPipe;
NotificationCenter.on('channel/' + channelName + '/message', function (data) {
Nc.on('channel/' + channelName + '/message', function (data) {
channelPipe.send('channel', data);
}, this);
// sending info to user
NotificationCenter.on('user/joined', function (user) {
Nc.on('user/joined', function (user) {
/*
NotificationCenter.on('channel/' + channelName + '/user/' + user.id, function (recipient, data) {
Nc.on('channel/' + channelName + '/user/' + user.id, function (recipient, data) {
channelPipe.send(recipient, data);
}, this);
*/
@ -81,11 +81,11 @@ function (User, Channel, PipeToChannel, NotificationCenter) {
}, this);
NotificationCenter.on('user/left', function (user) {
Nc.on('user/left', function (user) {
channelPipe.send('channel', { releaseUser: user.id });
}, this);
NotificationCenter.on('user/controlCommand', function (userId, data) {
Nc.on('user/controlCommand', function (userId, data) {
channelPipe.sendToUser(userId, data);
}, this);

View file

@ -3,7 +3,7 @@ define([
"child_process"
],
function (NotificationCenter, childProcess) {
function (Nc, childProcess) {
var fork = childProcess.fork;
@ -13,7 +13,6 @@ function (NotificationCenter, childProcess) {
try {
this.channelPipe = fork('channel.js');
console.log(this.channelPipe)
} catch (err) {
throw 'Failed to fork channel! (' + err + ')';
}
@ -48,7 +47,7 @@ function (NotificationCenter, childProcess) {
}
PipeToChannel.prototype.onMessage = function (message) {
NotificationCenter.trigger(message.recipient + '/message', message.data);
Nc.trigger(message.recipient + '/message', message.data);
}
return PipeToChannel;

View file

@ -4,7 +4,7 @@ define([
"Lib/Utilities/NotificationCenter"
],
function (Parent, ProtocolHelper, NotificationCenter) {
function (Parent, ProtocolHelper, Nc) {
function User (socketLink, coordinator) {
Parent.call(this, socketLink.id);
@ -16,7 +16,7 @@ function (Parent, ProtocolHelper, NotificationCenter) {
socketLink.on('message', this.onMessage.bind(this));
socketLink.on('disconnect', this.onDisconnect.bind(this));
NotificationCenter.on("user/" + this.socketLink.id + "/message", this.socketLink.send, this.socketLink);
Nc.on("user/" + this.socketLink.id + "/message", this.socketLink.send, this.socketLink);
}
User.prototype = Object.create(Parent.prototype);
@ -47,12 +47,12 @@ function (Parent, ProtocolHelper, NotificationCenter) {
User.prototype.onGameCommand = function(options) {
// repacking for transport via pipe
var message = ProtocolHelper.encodeCommand("gameCommand", options);
NotificationCenter.trigger("user/controlCommand", this.id, message);
Nc.trigger("user/controlCommand", this.id, message);
};
User.prototype.onPing = function(timestamp) {
var message = ProtocolHelper.encodeCommand("pong", timestamp);
NotificationCenter.trigger("user/" + this.socketLink.id + "/message", message);
Nc.trigger("user/" + this.socketLink.id + "/message", message);
};
return User;