Skip to content
Snippets Groups Projects
Commit bf0cc3b9 authored by Moritz Langenstein's avatar Moritz Langenstein
Browse files

(ml5717) Switched WebRTC layer to liowebrtc and signalbuddy

parent 591a98bf
No related branches found
No related tags found
No related merge requests found
[submodule "src/signalbuddy"]
path = src/signalbuddy
url = git@gitlab.doc.ic.ac.uk:sweng-group-15/signalbuddy.git
[submodule "src/rtcpeerconnection"]
path = src/rtcpeerconnection
url = git@gitlab.doc.ic.ac.uk:sweng-group-15/rtcpeerconnection.git
[submodule "src/liowebrtc"]
path = src/liowebrtc
url = git@gitlab.doc.ic.ac.uk:sweng-group-15/liowebrtc.git
This diff is collapsed.
......@@ -13,14 +13,16 @@
"start": "http-server -c-1 -p 12345 public",
"test": "jest",
"test-changed": "jest --only-changed",
"test-coverage": "jest --coverage"
"test-coverage": "jest --coverage",
"lint": "jshint .",
"validate": "npm ls"
},
"dependencies": {
"d3-shape": "^1.3.5",
"http-server": "^0.11.1",
"peer": "git+https://github.com/peers/peerjs-server.git",
"peerjs": "^1.1.0",
"liowebrtc": "file:src/liowebrtc",
"uuid": "^3.3.3",
"webrtc-adapter": "^4.0.0",
"y-array": "^10.1.4",
"y-map": "^10.1.3",
"y-memory": "^8.0.9",
......@@ -31,6 +33,12 @@
"jest": "^24.9.0",
"prettier": "^1.18.2",
"webpack": "^4.41.0",
"webpack-cli": "^3.3.9"
}
"webpack-cli": "^3.3.9",
"signalbuddy": "file:src/signalbuddy"
},
"pre-commit": [
"lint",
"validate",
"test"
]
}
......@@ -18,9 +18,8 @@ Y({
},
connector: {
name: "webrtc",
host: "localhost",
port: 3000,
path: "/api",
url: "localhost:8888",
room: "imperial",
},
share: {
drawing: "Map",
......
Subproject commit 14adace866d4c71c5a9e5e39129f770670d78427
Subproject commit 41fd1e2220d45b3d869b189dc836b9384e2a36fc
Subproject commit baa85f58bfa2e8d8336788bc1779f7a12b97bff5
/* global Y */
"use strict"
import { peerjs } from "peerjs"
const { Peer } = peerjs
import LioWebRTC from "liowebrtc"
function extend(Y) {
class WebRTC extends Y.AbstractConnector {
......@@ -19,18 +18,24 @@ function extend(Y) {
}
initialiseConnection() {
var peer = new Peer({
host: this.webrtcOptions.host,
port: this.webrtcOptions.port,
path: this.webrtcOptions.path,
const webrtc = new LioWebRTC({
url: this.webrtcOptions.url,
dataOnly: true,
network: {
minPeers: 4,
maxPeers: 8,
},
})
this.peer = peer
var self = this
this.peers = new Map()
this.webrtc = webrtc
const self = this
peer.on("open", function(id) {
//console.log("My peer ID is: " + id)
webrtc.on("ready", () => {
webrtc.joinRoom(self.webrtcOptions.room)
})
webrtc.on("joinedRoom", () => {
const id = webrtc.getMyId()
for (var f of self.userEventListeners) {
f({ action: "userID", id: id })
......@@ -39,42 +44,26 @@ function extend(Y) {
self.setUserId(id)
})
peer.on("connection", function(dataConnection) {
self.initialiseChannel(dataConnection)
// Cannot use createdPeer here as y-js will then try to send data before the channel is open
webrtc.on("channelOpen", (dataChannel, peer) => {
self.userJoined(peer.id, "master")
})
}
connectToPeer(uid) {
this.initialiseChannel(this.peer.connect(uid))
}
initialiseChannel(dataConnection) {
var self = this
dataConnection.on("open", function() {
//console.log("Connected to peer " + dataConnection.peer)
self.peers.set(dataConnection.peer, dataConnection)
self.userJoined(dataConnection.peer, "master")
webrtc.on("receivedPeerData", (type, message, peer) => {
self.receiveMessage(peer.id, message)
})
dataConnection.on("data", function(data) {
//console.log("Message from peer " + dataConnection.peer + ":", data)
self.receiveMessage(dataConnection.peer, data)
webrtc.on("removedPeer", (peer) => {
self.userLeft(peer.id)
})
}
dataConnection.on("close", function() {
//console.log("Disconnected from peer " + dataConnection.peer)
self.peers.delete(dataConnection.peer)
self.userLeft(dataConnection.peer)
})
connectToPeer(/*uid*/) {
// currently deprecated
}
disconnect() {
this.peer.destroy()
this.peers = new Map()
this.webrtc.quit()
super.disconnect()
}
......@@ -86,33 +75,11 @@ function extend(Y) {
}
send(uid, message) {
//console.log("Sending message", message, "to " + uid)
var self = this
var send = function() {
// check if the clients still exists
var peer = self.peers.get(uid)
if (peer) {
try {
peer.send(message)
} catch (error) {
setTimeout(send, 500)
}
}
}
// try to send the message
send()
this.webrtc.whisper(this.webrtc.getPeerById(uid), "y-js", message)
}
broadcast(message) {
//console.log("Broadcasting message", message)
for (const uid of this.peers.keys()) {
this.send(uid, message)
}
this.webrtc.shout("y-js", message)
}
isDisconnected() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment