From 68286c2b12c0ed34fa5afc6a9af0bfc000566e1b Mon Sep 17 00:00:00 2001 From: DoctorBud Date: Sun, 5 Jul 2020 22:10:18 -0700 Subject: [PATCH] - Adds 'make run-pretty' option to format log output in a more human-readable way. - Fixes typos in a couple places - Adds static/examples/mirror.html, which synthesizes a video source and acts as a peer. - Adds links to other examples to bottom of static/index.html - Adds js/mirrormedia.js which uses a Canvas to create a peer video stream. - In peering.js, add a 1-second delay before manually firing .play() on a newly created video element. This resolves random issues where even an autoplay video element doesn't start playing automatically. --- golang/Makefile | 6 ++ golang/pkg/signaling/room_node.go | 4 +- golang/pkg/signaling/websocket_peer.go | 2 +- golang/static/examples/mirror.html | 130 +++++++++++++++++++++++++ golang/static/index.html | 10 +- golang/static/js/mirrormedia.js | 25 +++++ golang/static/js/peering.js | 7 ++ 7 files changed, 180 insertions(+), 4 deletions(-) create mode 100644 golang/static/examples/mirror.html create mode 100644 golang/static/js/mirrormedia.js diff --git a/golang/Makefile b/golang/Makefile index 0ce1abf..db0615e 100644 --- a/golang/Makefile +++ b/golang/Makefile @@ -35,3 +35,9 @@ run: build run-debug: build ENV=local ./backend + +run-pretty: build + # open http://localhost:3001 + ENV=local ./backend 2>&1 | jq --raw-output '[("# " + .level + (" " * 10))[0:10], (.func + (" " * 20))[0:20], .msg] | @tsv' + + diff --git a/golang/pkg/signaling/room_node.go b/golang/pkg/signaling/room_node.go index 186db3d..95917a1 100644 --- a/golang/pkg/signaling/room_node.go +++ b/golang/pkg/signaling/room_node.go @@ -63,9 +63,9 @@ func (r *Room) Receive(message Message) { var group ReceiverGroup // When joining a group, make sure to remove them from their previous group - recevier := member.GetParent() + receiver := member.GetParent() if group != nil { - group = r.GetGroup(recevier.ID()) + group = r.GetGroup(receiver.ID()) group.RemoveMember(member) member.SetParent(nil) } diff --git a/golang/pkg/signaling/websocket_peer.go b/golang/pkg/signaling/websocket_peer.go index ae22e4f..fcbe4b3 100644 --- a/golang/pkg/signaling/websocket_peer.go +++ b/golang/pkg/signaling/websocket_peer.go @@ -49,7 +49,7 @@ func NewWebsocketPeer(conn WebsocketConn, parent ReceiverNode) *WebsocketPeer { func (p *WebsocketPeer) Receive(message Message) { logrus.Debugf("queueing message for %s", p.ID()) p.messages <- message - logrus.Debugf("finshed queuing message for %s", p.ID()) + logrus.Debugf("finished queuing message for %s", p.ID()) } func (p *WebsocketPeer) PumpWrite() { diff --git a/golang/static/examples/mirror.html b/golang/static/examples/mirror.html new file mode 100644 index 0000000..4a07bc1 --- /dev/null +++ b/golang/static/examples/mirror.html @@ -0,0 +1,130 @@ + + + + + + + + + + + + + + + + + Your browser does not support the HTML5 canvas tag. + + +
+ +
+ + + + + diff --git a/golang/static/index.html b/golang/static/index.html index 0d79c2f..0d61d6b 100644 --- a/golang/static/index.html +++ b/golang/static/index.html @@ -62,9 +62,17 @@ signals.connect((isHTTPS ? "ws" : "wss") + "://" + location.host + "/room") window.addEventListener("unload", function () { signals.sendLeave() - }); + }) }) + +
+ audio.html + groups.html + local.html + peer.html + stun.html + mirror.html diff --git a/golang/static/js/mirrormedia.js b/golang/static/js/mirrormedia.js new file mode 100644 index 0000000..f516fd0 --- /dev/null +++ b/golang/static/js/mirrormedia.js @@ -0,0 +1,25 @@ + +// eslint-disable-next-line no-unused-vars +class MirrorMedia { + constructor(video, canvas) { + this.id = video.id + this.video = video + this.canvas = canvas + this.stream = null + } + + async setupMedia() { + const stream = this.canvas.captureStream(25) + + this.stream = stream + + this.video.srcObject = stream + } + + getStream() { + return this.stream + } + + async onConnected() {} + async onDisconnected() {} +} diff --git a/golang/static/js/peering.js b/golang/static/js/peering.js index 6a3a060..5e6b64e 100644 --- a/golang/static/js/peering.js +++ b/golang/static/js/peering.js @@ -73,9 +73,16 @@ class Peering { let video = document.createElement("video") video.id = peerId video.autoplay = true + video.controls = true + video.muted = true + video.poster = 'https://upload.wikimedia.org/wikipedia/commons/d/d3/WUERFEL5_0-_bis_5-dimensionale_Wuerfelanaloge.png' this.videosElm.appendChild(video) + setTimeout(() => { + video.play() + }, 1000) + peer.addEventListener('icecandidate', ({ candidate }) => { if (candidate) { this.signals.sendICECandidate(peerId, candidate)