Last active
October 29, 2023 05:26
-
-
Save piyushranjan/1204bc579b7c1f5a3e84 to your computer and use it in GitHub Desktop.
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
window={}; | |
window.BlobBuilder = require("BlobBuilder"); | |
location={}; | |
location.protocol="http"; | |
BinaryPack = require("binary-pack"); | |
XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; | |
var wrtc = require("wrtc"); | |
RTCPeerConnection = wrtc.RTCPeerConnection; | |
RTCSessionDescription = wrtc.RTCSessionDescription; | |
RTCIceCandidate = wrtc.RTCIceCandidate; | |
WebSocket = require('ws'); | |
var peerClient =require("./peer.js"); | |
var peerConfig = { | |
key: 'testtest', | |
host: 'localhost', | |
port: 9000, | |
debug: 3 | |
}; | |
var sid = "testsid"; | |
var server = new peerClient.Peer(sid, peerConfig); | |
var cid = Math.random().toString(36).substring(7); | |
var client = new peerClient.Peer(cid, peerConfig); | |
function setupServer(server){ | |
server.on('connection', function(e){ | |
console.log('server connection', e); | |
e.send({connectTime: (new Date()).getTime()}); | |
e.on('data', function(m){ | |
console.log("got ping. sending pong"); | |
e.send({pongTime: (new Date()).getTime()}) | |
}); | |
}); | |
server.on('connect', function(e){ | |
console.log("server connect"); | |
}); | |
server.on('call', function(e){ | |
console.log("server got call"); | |
}); | |
server.on('close', function(e){ | |
console.log("server got close"); | |
}); | |
} | |
setupServer(server); | |
client.on('connection', function(e){ | |
console.log('client connection'); | |
}); | |
client.on('call', function(call) { | |
console.log("client called"); | |
call.answer(); | |
call.on('stream', function(stream){ | |
console.log("stream"); | |
}); | |
}); | |
client.on("open", function(e){ | |
console.log("client open"); | |
console.log(e); | |
console.log("sending"); | |
clientConn.send({ping: (new Date()).getTime()}); | |
setInterval(function(){ | |
console.log("sending"); | |
clientConn.send({ping: (new Date()).getTime()}) | |
}, 1000); | |
}); | |
clientConn = client.connect(sid); | |
client.on("data", function(d){ | |
console.log("got data"); | |
}); | |
client.on("error", function(){ | |
console.log("got error") | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment