This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
socket.on('offer-made', function (data) { | |
offer = data.offer; | |
pc.setRemoteDescription(new sessionDescription(data.offer), function () { | |
pc.createAnswer(function (answer) { | |
pc.setLocalDescription(new sessionDescription(answer), function () { | |
console.log('MAKE ANSWER'); | |
socket.emit('make-answer', { | |
answer: answer, | |
to: data.socket |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// chat-server.ts | |
socket.on('make-offer', function (data) { | |
socket.to(data.to).emit('offer-made', { | |
offer: data.offer, | |
socket: socket.id | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// public/index.js | |
var peerConnection = window.RTCPeerConnection || | |
window.mozRTCPeerConnection || | |
window.webkitRTCPeerConnection || | |
window.msRTCPeerConnection; | |
var sessionDescription = window.RTCSessionDescription || | |
window.mozRTCSessionDescription || |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// public/index.js | |
socket.on('remove-user', function (id) { | |
var div = document.getElementById(id); | |
document.getElementById('users').removeChild(div); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private listen(): void { | |
... | |
this.io.on('connection', (socket) => { | |
socket.broadcast.emit('add-users', { | |
users: [socket.id] | |
}); | |
socket.on('disconnect', () => { | |
this.socketsArray.splice(this.socketsArray.indexOf(socket.id), 1); | |
this.io.emit('remove-user', socket.id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// chat-server.ts | |
export class ChatServer { | |
... | |
private socketsArray = []; | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// public/index.js | |
var socket = io.connect('http://localhost:5000'); | |
socket.on('add-users', function (data) { | |
for (var i = 0; i < data.users.length; i++) { | |
var el = document.createElement('div'), | |
id = data.users[i]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// public/index.js | |
var socket = io.connect('http://localhost:5000'); | |
socket.on('add-users', function (data) { | |
for (var i = 0; i < data.users.length; i++) { | |
var el = document.createElement('div'), | |
id = data.users[i]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var socket = io.connect('http://localhost:5000'); | |
// public/index.js | |
socket.on('add-users', function (data) { | |
for (var i = 0; i < data.users.length; i++) { | |
var el = document.createElement('div'), | |
id = data.users[i]; | |
el.setAttribute('id', id); | |
el.innerHTML = id; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private listen(): void { | |
this.server.listen(this.port, () => { | |
console.log('Running server on port %s', this.port); | |
}); | |
this.io.on('connection', (socket) => { | |
socket.broadcast.emit('add-users', { | |
users: [socket.id] | |
}); | |
}); | |
} |