How to use the now.on function in now

To help you get started, we’ve selected a few now examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Flotype / now / examples / express_example / app.js View on Github external
app.listen(8080);
console.log("Express server listening on port %d", app.address().port);


// NowJS component
var nowjs = require("now");
var everyone = nowjs.initialize(app);


nowjs.on('connect', function(){
      console.log("Joined: " + this.now.name);
});


nowjs.on('disconnect', function(){
      console.log("Left: " + this.now.name);
});

everyone.now.distributeMessage = function(message){
  everyone.now.receiveMessage(this.now.name, message);
};
github chaoscollective / Space_Editor / app.js View on Github external
html += "window.addEventListener('message', receiveMessage, false);";
  html += "";
  res.send(html);
  */
  res.send(JSON.stringify(nowUsersList));
});
// ------------------------------------------------------------
// ------------------------------------------------------------
var localFileIsMostRecent = []; // an array of flags indicating if the file has been modified since last save.
var nowjs     = require("now");
var everyone  = nowjs.initialize(server);
// ------ REALTIME NOWJS COLLABORATION ------
//var nowcollab = require("../CHAOS/nowcollab");
//nowcollab.initialize(nowjs, everyone, true);
//-------------------------------------------
nowjs.on('connect', function () { 
  //console.log("CONNECT    > " + this.user.clientId);
  this.user.teamID      = teamID;
  if(this.now.teamID != ''){
    this.user.teamID = this.now.teamID;
  }
  //console.log(this.user);
  //console.log(everyone.users);
  //console.log(" >> PROJECT="+this.user.teamID);
  // hack to get out best guess at the user (since now.js doesn't give us the request object or session!);
  var u = {}; //(Auth || {}).getUserFromCache(decodeURIComponent(this.user.cookie['_chaos.auth'])) || {};
  // now populate it..
  this.user.about       = {};
  this.user.about._id   = u._id || 0;
  this.user.about.name  = u.nameGiven || u.displayName  || this.user.cookie["_username"] || "???";
  this.user.about.email = u.emailPrimary || "anon@chaoscollective.org";
  // -----
github hughanderson4 / smartjs / server / connectionHandlers / groupHandler.js View on Github external
};
    console.log('broadcast message to all: ' + Util.inspectObject(dto));
    if (everyone && everyone.now && everyone.now.eventServerToClient) {
        everyone.now.eventServerToClient('chat.message', dto, serverClientId);
    }
}

// each time a new nowjs group is created, attach to it's leave handler
Nowjs.on('newgroup', function (group) {
    console.log('Nowjs group created: ' + group.groupName);
    group.on('leave', function () {
        notifyGroupRemoval(group, this.user.clientId);
    });
});

Nowjs.on('disconnect', function () {
    var currentClientId = this.user.clientId;

    console.log('disconnect notice, this.getGroups=' + this.getGroups);
    console.log('this.now=' + Util.inspectObject(this.now));
    console.log('this.user=' + Util.inspectObject(this.user));
    console.log('this.groups=' + Util.inspectObject(this.groups));

    this.getGroups(function (groups) {
        console.log('discod user belongs to groups:' + Util.inspectObject(groups));
        for (var i = 0; i < groups.length; i++) {
            notifyGroupRemoval(groups[i], currentClientId);
        }
    });
});

// feature to broadcast the time periodically
github fyhao / Real-time-video-sharing-built-on-nowJS-and-Node.JS / web.js View on Github external
app.listen(process.env.PORT || 8080);

// include nowJS framework handler
var nowjs = require('now');

// initialize nowJS into everyone object
var everyone = nowjs.initialize(app);

// to create a unique key for each registered session name
var key = 0;

// to store each registered session name
var names = [];

// trigger when each client user connect to nowjs
nowjs.on('connect', function() {
	
	// for each client user, check if there has already associated name
	if(!this.now.name) {
		// generate a name for this new client user
		this.now.name = 'name' + ++key;
		
		// add this name into the global names object
		names.push(this.now.name);
	}
	
});

// trigger when each client user disconnect from nowjs
nowjs.on('disconnect', function() {
	// delete this client user name from the global names object
	util.deleteItem(names, this.now.name);
github Flotype / now / examples / helloworld_example / helloworld_server.js View on Github external
response.write(data);
    response.end();
  });
});
server.listen(8080);
var nowjs = require("now");
var everyone = nowjs.initialize(server);



nowjs.on("connect", function(){
  group.addUser(this.user.clientId);
  console.log("Joined: " + this.now.name);
});

nowjs.on("disconnect", function(){
  console.log("Left: " + this.now.name);
});

everyone.on('join', function(){
  console.log("joined " + this.now.name);
});


everyone.on('leave', function(){
  console.log("left " + this.now.name);
});




var group = nowjs.getGroup('x');
github pcottle / GeneticGPU / server.js View on Github external
});
});

var port = process.env.PORT || 8080;
server.listen(port);
console.log("server listening on port " + String(port));

var nowjs = require("now");
var everyone = nowjs.initialize(server, {
    socketio: {
        transports: ['xhr-polling', 'jsonp-polling']
    }
});


nowjs.on('connect', function () {
    this.now.firstRoom = "lobby";
    nowjs.getGroup(this.now.firstRoom).addUser(this.user.clientId);
});


nowjs.on('disconnect', function () {
    console.log("Someone left with client id", this.user.clientId);
});


roomInfo = {};
everyone.now.makeRoom = function (newRoom, equationInfo) {

    //we need to initialize some things about roomInnfo
    roomInfo[newRoom] = equationInfo;
github pcottle / GeneticGPU / server.js View on Github external
var nowjs = require("now");
var everyone = nowjs.initialize(server, {
    socketio: {
        transports: ['xhr-polling', 'jsonp-polling']
    }
});


nowjs.on('connect', function () {
    this.now.firstRoom = "lobby";
    nowjs.getGroup(this.now.firstRoom).addUser(this.user.clientId);
});


nowjs.on('disconnect', function () {
    console.log("Someone left with client id", this.user.clientId);
});


roomInfo = {};
everyone.now.makeRoom = function (newRoom, equationInfo) {

    //we need to initialize some things about roomInnfo
    roomInfo[newRoom] = equationInfo;

    this.now.receiveMessage("You have now made / updated the room " + newRoom + ", transferring you...");
    this.now.changeRoom(newRoom);
};

everyone.now.clearAllRooms = function () {
    roomInfo = {};
github pcottle / GeneticGPU / node / server.js View on Github external
response.writeHead(200, {'Content-Type':'text/html'}); 
          response.write(data);  
          response.end();
    });
});

var port = process.env.PORT || 8080;
server.listen(port);

console.log("running server on ",port);

var nowjs = require("now");
var everyone = nowjs.initialize(server, {socketio: {transports: ['xhr-polling', 'jsonp-polling']}});

nowjs.on('connect', function(){
    this.now.room = "lobby";
    nowjs.getGroup(this.now.room).addUser(this.user.clientId);
    console.log(this.now.name + " joined the lobby");
});

nowjs.on('disconnect', function(){
    console.log("Left: " + this.now.name + "from room", this.now.room);
});

everyone.now.changeRoom = function(newRoom){
    nowjs.getGroup(this.now.room).removeUser(this.user.clientId);
    nowjs.getGroup(newRoom).addUser(this.user.clientId);
    this.now.room = newRoom;
    this.now.receiveMessage("SERVER", "You're now in " + this.now.room);
    console.log(this.now.name, "joined the room ", this.now.room);
}
github pcottle / GeneticGPU / server.js View on Github external
var port = process.env.PORT || 8080;
server.listen(port);
console.log("server listening on port " + String(port));

var nowjs = require("now");
var everyone = nowjs.initialize(server, {socketio: {transports: ['xhr-polling', 'jsonp-polling']}});


nowjs.on('connect', function(){
  this.now.room = "room 1";
  nowjs.getGroup(this.now.room).addUser(this.user.clientId);
  console.log("Joined: " + this.user.clientId);
});


nowjs.on('disconnect', function(){
  console.log("Someone left with client id",this.user.clientId);
});


roomInfo = {};

everyone.now.makeRoom = function(newRoom,equationInfo) {

    if(roomInfo[newRoom])
    {
        this.now.receiveMessage("That room is already created!");
        return;
    }

    //we need to initialize some things about roomInnfo
    roomInfo[newRoom] = equationInfo;
github LastRose / nodejs-livechat / livechat / app.js View on Github external
if(undef != -1){
					groups.splice(undef,1);
				}
			})
		}
		everyone.now.setGroups(groups);
	});
}

nowjs.on('disconnect', function(){
			ind = admins.indexOf(this.user.clientId);
			if(ind != -1){			
				admins.splice(admins.ind,1);			
			}
})
nowjs.on('newgroup',function(group){
	  	console.log('You have successfully created the group `' + group.groupName + '`');
})
everyone.now.distributeMessage = function(message,groupname){
	group = nowjs.getGroup(groupname);
	group.now.receiveMessage(this.now.name, message, groupname);
}

//on admin connect add userID to array
//on list of groups
//remove users in admin array from lost of users in that group
//if the number of users in the group is 0, remove it from the list of groups.
//on admin disconnect, remove userid from admin array.

now

The command-line interface for Vercel

Apache-2.0
Latest version published 3 years ago

Package Health Score

59 / 100
Full package analysis