際際滷

際際滷Share a Scribd company logo
Project
PC PC
Node + socket.io
? node + socket.io
? Rails websocket / eventmachine
gem
how to start
? route:
<index.js>
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
console.log('get /');
});
app.get('/mobi', function(req, res){
res.sendFile(__dirname + '/index1.html');
console.log('get /mobi');
});
http.listen(3000, function(){
console.log('listening on *:3000');
});
how to start
? socket:
<index.html , index1.html>
var io = require('socket.io')(http);
io.on('connection', function(socket){
socket.on('chat message', function(msg){
io.emit('chat message', msg);
});
});
socket on html
<script src=/SkyWang5/nodejs-partysocket-demo/"https:/cdn.socket.io/socket.io-1.2.0.js"></
script>
<script>
var socket = io();
msg => socket.emit(`channel',msg);
msg => socket.on('channel', function(msg){});
</script>
youtube api
copy getting started html
https://developers.google.com/youtube/iframe_api_reference?
csw=1#pauseVideo
socket.on('chat message', function(msg){
if (msg == 'start')
player.playVideo();
if (msg == 'stop')
player.stopVideo();
});
index1.html socket.emit ¨start¨ / `stop¨
youtube
Event
?
EventListener
? window.orientation 0, 90, -90
Event
<index1.js>
window.addEventListener("orientationchange", function() {
var msg = {
orientation:window.orientation,
play :'start',
room :channel
};
if(angle !== msg.orientation){
angle = msg.orientation;
(msg.orientation < 0)? msg.play = 'start' : msg.play = 'stop';
socket.emit('linked', msg);
} //
}, false);
Event
<index.js>
io.on('connection', function(socket){
socket.on('linked', function(msg){
io.emit(msg.room, msg);
});
});
<index.js>
io.on('connection', function(socket){
socket.on('ask_channel', function(msg){
io.emit('ask_channel', msg);
}); // room
socket.on('answer_channel', function(msg){
io.emit('answer_channel', msg);
}); // room
socket.on('linked', function(msg){
io.emit(msg.room, msg);
console.log('linked='+msg.room);
}); // linked channel, room channel
});
<index.html>
socket.on('ask_channel', function(msg){
if(msg==randomValue){
socket.emit('answer_channel',msg);
$('h1').text("");
$('#tutorial').text(' -> ; -> ');
}
});
<index1.html>
$('form').submit(function(){
$('#er').text("");
code = $('#m').val();
socket.emit('ask_channel', code);
setTimeout(function(){
if(code !== channel) $('#er').text("
");},1000);
return false;
});
socket.on('answer_channel',function(msg){
if(code == msg) channel = code;
$('h1').text(" ~!")
});
var app = require(`express')();
express ??
express generater
:
? Ruby on Rails, HTML, CSS, Ajax, Nodejs, socket
? DataBase: MySQL, PostgreSQL
? Boostrap, jQuery
:
Frondend / Backend / DevOps
Github: https://github.com/jcsky/socketDemo
Facebook: jcsky.wang
Project
: facebook 9/3

More Related Content

Viewers also liked (10)

PPTX
Выбор правильной позиции
Unification_Ru
?
PPTX
Теория истории
Unification_Ru
?
PPS
Que fotos
jmpcard
?
PPTX
Las vocales
Jessica Bravo Bravo
?
PDF
MARKETINGROUP (2016)
Sergio Baray
?
PDF
Resume senior paint chemist 2016
Mohamed Wahhab
?
PPTX
Frankfurt: How to make organizations more valuable
Barrett Academy
?
DOC
David Arthur Campbell Resume
David Campbell
?
PPTX
?Qu└ es el BTL?
BONO.MD
?
PDF
Thomson Reuters Company Overview Deck
Karim Helmy
?
Выбор правильной позиции
Unification_Ru
?
Теория истории
Unification_Ru
?
Que fotos
jmpcard
?
MARKETINGROUP (2016)
Sergio Baray
?
Resume senior paint chemist 2016
Mohamed Wahhab
?
Frankfurt: How to make organizations more valuable
Barrett Academy
?
David Arthur Campbell Resume
David Campbell
?
?Qu└ es el BTL?
BONO.MD
?
Thomson Reuters Company Overview Deck
Karim Helmy
?

Nodejs party-socket demo