Beispiel #1
0
  function remove_Die(){
	  this.dice.splice(0,1);
    
    var windex;
    var winner;
    var living_count = 0;
    for(windex = 0; windex < tables[this.table].players.length && living_count < 2; windex = windex + 1){
        if(tables[this.table].players[windex].dice.length > 0){
          winner = windex;
          living_count = living_count + 1;
        }
    } 
    if(living_count < 2){
      tables[this.table].reset_Ready();
      tables[this.table].in_game = false;
      pusher.trigger("table" + this.table, "win", {player: tables[this.table].players[winner].nickname});
    }
    if(this.dice.length == 1 && !this.has_obliged){
      this.has_obliged = true;
      pusher.trigger("table" + this.table, "obligo", {});
    }
    else{
       pusher.trigger("table"+this.table, "not_obligo", {});
    }
    
  }
Beispiel #2
0
app.post('/music',function(request,response){
	if(request.body.command == "play"){
		pusher.trigger('macbook', 'music', {
		  "command": "play"
		});
	}
	else{
		pusher.trigger('macbook', 'music', {
		  "command": "stop"
		});
	}
});
Beispiel #3
0
function send_Table_Info(){
  for(temp = 0; temp < 4; temp = temp + 1){
    tables_info[temp] = tables[temp].players.length;
    tables_in_game[temp] = tables[temp].in_game;
  }
  pusher.trigger('lobby', 'update_tables_info', {tables_info: tables_info, tables_in_game: tables_in_game});
}
Beispiel #4
0
exports.trigger = function (req, res) {
  var channel = req.params.channel;

  pusher.trigger(channel, 'test_event', { "message": "hello world" });

  return res.send(200, 'Triggered!');
}
Beispiel #5
0
 /**
  * 推送消息
  * @param msg 消息
  */
 pushMessage(params){
     if(!params.relationId){
         return;
     }
     let pushevent = 'moment-push';
     this.messagePusher.trigger(params.relationId, pushevent, params);
 }
Beispiel #6
0
 /**
  * 发送消息action
  */
 async sendAction(){
     if(!this.isPost()){
         this.fail("INCORRECT_AJAX_TYPE_POST");
         return;
     }
     let params = this.post();
     // 检查对话的关系链
     let relationItem = await this.model("chatrelation").where({relationId:params.relationId}).find();
     if(think.isEmpty(relationItem)){
         this.fail("RELATION_NOT_EXIST");
         return;
     }
     if(relationItem.collectionId.indexOf(params.speakerId) == -1 || relationItem.collectionId.indexOf(params.audienceId) == -1){
         this.fail("RELATION_NOT_MATCH");
         return;
     }
     // 保存消息
     think.extend(params,{
         status:0,
         create_time:new Date().getTime(),
         update_time:new Date().getTime()
     });
     let chatId = await this.model("chat").add(params);
     if(think.isEmpty(chatId)){
         this.fail("MESSAGE_SEND_FAIL");
         return;
     }
     this.messagePusher.trigger(params.relationId, 'moment-push', params);
     this.success({
         result:true,
         chatId:chatId,
         message:"发送消息成功!"
     });
 }
 }, function (err, data) {
     if (err) {
         if (channel && event) {
             pusher.trigger(channel, event, {
                 "message": "error"
             });
             console.error(err.message);
         }
     } else {
         if (channel && event) {
             pusher.trigger(channel, event, {
                 "message": apiKey
             });
         }
     }
 });
Beispiel #8
0
  handler: function (request, reply) {
    console.log(request.payload);

    pusher.trigger('sendgrid-pusher-demo', 'inbound', request.payload);

    reply({success: true});
  }
 _.each(resGetDevice, function(device){
     var deviceId = null;
     if (_.isObject(device) && !_.isEmpty(device)){
         deviceId = device._id;
         if (deviceId) Pusher.trigger(deviceId, 'eyex_sync', syncType);
     }
 })
Beispiel #10
0
app.post('/api/', function(request, response) {
	var input = request.body;

	pusher.trigger( 'chat_channel', 'message', { msg: input.message } );
	console.log(input);

  response.send("done");
});
Beispiel #11
0
app.put('/readonly/off', bodyParser.json(), (req, res) => {
  if(!req.session.auth) return res.sendStatus(401)
  readOnly = false
  pusher.trigger('codealong', 'update', {
    readOnly: readOnly
  })
  res.send('ok')
})
Beispiel #12
0
	function calzo(seat){
    pusher.trigger("table" + this.id, 'show_hands', {players: this.players});
		var temp_count = 0;
    var lost;
		for(temp = 0; temp < this.players.length; temp = temp + 1){
			for(var temp1 = 0; temp1 < this.players[temp].dice.length; temp1 = temp1 + 1){
				if(this.players[temp].dice[temp1] == 1 || this.players[temp].dice[temp1] == this.current_dice.dice_type){
					temp_count = temp_count + 1;
				}
			}
		}
		if(temp_count == this.current_dice.dice_count){
			this.current_turn = seat;
			this.players[this.current_turn].add_Die();
      lost = false;
		}
		else{
			this.current_turn = seat;
			this.players[this.current_turn].remove_Die();
      lost = true;
		while(this.players[this.current_turn].dice.length == 0){
			  this.current_turn = this.current_turn + 1;
			  if(this.current_turn > this.players.length - 1){
				  this.current_turn = 0;
			  }
		 }
	  }
    if(lost){
        pusher.trigger("table" + this.id, 'chat', {"message": this.players[this.seat].nickname + " called calzo!<br>" 
    										 + "There were " + temp_count + " " + this.current_dice.dice_type + "'s<br>"
    										 + "Last bet was " + this.current_dice.dice_count + " " + this.current_dice.dice_type + "'s<br>"
                         + this.players[this.seat].nickname + " lost a die!<br>"});
    }
    else{
      pusher.trigger("table" + this.id, 'chat', {"message": this.players[this.seat].nickname + " called calzo!<br>" 
    										 + "There were " + temp_count + " " + this.current_dice.dice_type + "'s<br>"
    										 + "Last bet was " + this.current_dice.dice_count + " " + this.current_dice.dice_type + "'s<br>"
                         + this.players[this.seat].nickname + " gained a die!<br>"});
    }
    var players_dice_count = new Array();
    for(temp = 0; temp < this.players.length; temp = temp + 1){
      players_dice_count.push(this.players[temp].dice.length);
    }
    pusher.trigger("table" + this.id, "new_hand", {start_seat: + this.current_turn, players_dice_count: players_dice_count});                   
	}
Beispiel #13
0
 p.save( function( err ) {
     if( !err ) {
         console.log( 'created' );
     } else {
         console.log( err );
     }
     pusher.trigger("test", 'my_event', {
         "message": "Manchester Playlist has been added to Spotify"
     });
 });
app.get('/message', function (req, res) {

  var user_msg = req.query.user_msg;
  var sentiment = req.query.sentiment;

  pusher.trigger('test_channel', 'my_event', {
    "message": user_msg,
    "sentiment": sentiment
  });
});
var interval = setInterval( function() {
	console.log( 'triggering: ' + (count + 1 ) )
	var data = getRandomData();
	pusher.trigger( 'btc-usd-demo', 'new-price', data );
	++count;
	if( count == argv.count ) {
		console.log( 'triggering complete' );
		clearInterval( interval );
	}
}, ( argv.interval * 1000 ) );
Beispiel #16
0
function push(){
	var pusher = new Pusher({
	  appId: '56169',
	  key: 'b96395f1fe8878856881',
	  secret: '4e82336ec7d77b5113d8'
	});

	pusher.trigger('presence-test', 'update', {
	  "message": "hello world"
	});
}
Beispiel #17
0
stream.on('tweet', function (tweet) {
	console.log(tweet)

	pusher.trigger('sentibot', 'tweet', {
  		"message": tweet.text,
  		"screenname" : tweet.user.screen_name,
  		"location" : tweet.user.location,
  		"created" : tweet.created_at,
  		"profileimage" : tweet.user.profile_image_url
	});
})
Beispiel #18
0
    handler: function (request, reply) {

      if (dbList[request.params.database].indexOf(request.query.database.toLowerCase()) >= 0) {
        pusher.trigger(request.params.database, 'new-entry', {
          "database": request.query.database
        });
      }
      return reply({
        response: dbList[request.params.database].indexOf(request.query.database.toLowerCase()),
      });
    },
Beispiel #19
0
 .then(function (data) {
     spotifyApi.addTracksToPlaylist(obj.spotify_id, hghg.playlistID, ["spotify:track:" + data.tracks.items[1].id])
         .then(function (data) {
             console.log('Added tracks to ' + obj.username + ' playlist!');
         }, function (err) {
             console.log('Something went wrdddddong!', err);
         });
     pusher.trigger("test", 'my_event', {
         "message": "New Song Added to Manchester Playlist"
     });
     console.log('Search tracks by "Love" in the artist name', data.tracks.items[1].id);
 }, function (err) {
Beispiel #20
0
app.put('/input', parser, bodyParser.json(), (req, res) => {
  if(!req.session.auth) return res.sendStatus(401)
  res.sendStatus(200)

  if(req.body.dial) {
    redis.hset('input', 'dial', req.body.dial)
    pusher.trigger('input','dial',req.body.dial)
  }
  if(req.body.A) {
    redis.hset('input', 'a', req.body.A)
    pusher.trigger('input','a',req.body.A)
  }
  if(req.body.B) {
    redis.hset('input', 'b', req.body.B)
    pusher.trigger('input','b',req.body.B)
  }

  // auto expire in 40 mins
  redis.expire('input', 60*40)

})
Beispiel #21
0
function pusherCall(coordinates){
	pusher.trigger('lastlocation', 'data', {"message": coordinates});
	var timer = setTimeout(function(){
		if(keepCalling){
			tracker(coordinates);
		}
		else{
			clearInterval(timer);
		}
	},
	delay);
}
Beispiel #22
0
        .then(pokemon => {
          const data = {
            id: pokemonId,
            name: pokemon.name,
            sprite: `https://pokeapi.co/media/sprites/pokemon/${pokemonId}.png`,
            coordinates: [lng, lat],
            expires: parseInt((new Date()).getTime() + duration, 10),
            hp: pokemon.stats.find(stat => stat.stat.name === 'hp').base_stat,
            types: pokemon.types.map(type => type.type.name[0] + type.type.name.substring(1))
          }

          pusher.trigger(bounds, 'encounter', data);
        });
Beispiel #23
0
  var activity = new Activity("chat-message", options["text"], options, function(result) {
    var data = result.getMessage();

    // Trigger message
    var response = pusher.trigger("question", "chat_message", data);

    var status = 200;
    var body = {"activity": data, "pusherResponse": response};

    res.setHeader("Cache-Control", "no-cache, must-revalidate");
    res.setHeader("Content-Type", "application/json");

    res.send(status, body);
  });
Beispiel #24
0
    }, (err) => {
      if (err) {
        return callback(err);
      }

      pusher.trigger(
        // TODO: verify this a little
        event['body-json'].target, // 'cluster_' + clusterId,
        'message',
        event['body-json'].message,
        event['body-json'].socketId);

      callback(null, true);
    });
Beispiel #25
0
 p.save( function( err ) {
     if( !err ) {
         console.log( 'created' );
     } else {
         console.log( err );
     }
     pusher.trigger("test", 'my_event', {
         "message": "London Euston Playlist Added"
     });
     spotifyApi.addTracksToPlaylist(obj.spotify_id, data.id, ["spotify:track:4iV5W9uYEdYUVa79Axb7Rh", "spotify:track:1301WleyT98MSxVHPZCA6M"])
         .then(function(data) {
             console.log('Added tracks to playlist!');
         }, function(err) {
             console.log('Something went wrdddddong!', err);
         });
 });
			var id = coll.insert(toInsert, function(error, saved) {
				if (error) {
					res.send(500);
				}
				else {
					var pusher = new Pusher({
					  appId: 'INSERT_ID',
					  key: 'INSERT_KEY',
					  secret: 'INSERT_SECRET',
					});
					pusher.trigger('test_channel', 'my_event', {
					  "side": side
					});
					res.send(200);
				}
		    });
Beispiel #27
0
 p.save( function( err ) {
     if( !err ) {
         console.log( 'created' );
     } else {
         console.log( err );
     }
     spotifyApi.addTracksToPlaylist(obj.spotify_id, data.id, ["spotify:track:4iV5W9uYEdYUVa79Axb7Rh", "spotify:track:1301WleyT98MSxVHPZCA6M"])
         .then(function(data) {
             console.log('Track Added to Manchester Picadily Playlist');
         }, function(err) {
             console.log('Something went wrdddddong!', err);
         });
     pusher.trigger("test", 'my_event', {
         "message": "New Play List Created"
     });
 });
Beispiel #28
0
app.post('/store', limiter, bodyParser.json(), parser, (req, res) => {
  if(!req.session.pusher_user_id) return res.sendStatus(401)
  if(!(req.body.key && req.body.value)) return res.sendStatus(400)

  var row = store(
    req.session.pusher_user_id,
    req.body.key,
    req.body.value
  )

  if(row) {
    pusher.trigger('codealong_store', 'add', {
      rows:[row]
    })
  }

  res.sendStatus(200)
})
Beispiel #29
0
router.post('/messages/new/', cors(), function(req, res)
{
	res.header("Access-Control-Allow-Origin", "*");
	res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
	res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
	res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');

	if(req.body.channel != null && req.body.event != null && req.body.text != null && req.body.autor != null && req.body.socketid != null)
	{
		pusher.trigger(req.body.channel, req.body.event, {text: req.body.text, autor: req.body.autor}, req.body.socketid);
		res.json({message: "Perfect"})
		console.log("[Canal: "+req.body.channel +"] [Evento: "+ req.body.event +"] "+ req.body.autor +": "+req.body.text)
	}else
	{
		res.json({ error: 'Incomplete requeriments' }); 
	}
	
}
Beispiel #30
0
app.post('/trigger', function(req, res) {
  var messageText = req.body.message;
  
  /*
  TODO: implement checks to determine if the user is:
  1. Authenticated with the app
  2. Allowed to trigger on the channel
  3. Sanitize any additional data that has been recieved and is to be used

  If so, proceed...
  */
  
  var eventData = {
    message: messageText
  };
  pusher.trigger('my-channel', 'my-event', eventData);
  
  res.send('OK');
});