Anton Shestakov <av6@dwimlabs.net>, Wed, 01 Nov 2017 00:50:57 +0800
Makefile: use file targets more, results in incremental building
Less work to do when only some files get changed, but more work when building
from scratch. But, multiple compilers can run in parallel.
coffee/webrtc.coffee
Permissions: -rw-r--r--
class Tram.WebRTCInterface constructor: (@contact) -> @peerJid = @contact.get('jid') init: (@initiator, constraints) -> if constraints.audio || constraints.video navigator.getUserMedia(constraints, @connect, @fail) @call = calls.add(jid: @peerJid) @pc = new RTCPeerConnection(iceServers: Tram.config.iceServers) @call.set('local/stream', stream) @pc.onicecandidate = (event) => @sendPayload(event.candidate, 'ice') @pc.onaddstream = (event) => @call.set('remote/stream', event.stream) @contact.set('callstate', 'established') el = stanza.getElementsByTagNameNS(Tram.NS.WEBRTC, 'payload')[0] signal = JSON.parse(el.firstChild.nodeValue) if signal.type is 'offer' else if signal.type is 'answer' @pc.addIceCandidate(new RTCIceCandidate(signal)) sendPayload: (data, type) -> payload = JSON.stringify(data) msg = $msg(to: @peerJid, type: 'chat') .c('payload', xmlns: Tram.NS.WEBRTC, type: type).t(payload) msg = $msg(to: @peerJid, type: 'chat') .c('intent', xmlns: Tram.NS.WEBRTC).t(intent) @pc.createOffer((offer) => @pc.setLocalDescription(offer, => @sendPayload(@pc.localDescription, 'offer') @pc.setRemoteDescription(new RTCSessionDescription(offer), => @pc.createAnswer((answer) => @pc.setLocalDescription(answer, => @sendPayload(@pc.localDescription, 'answer') receiveAnswer: (answer) -> @pc.setRemoteDescription(new RTCSessionDescription(answer)) @contact.unset('callstate') @call.unset('remote/stream') @call.unset('local/stream') #@pc?.removeStream?(@rstream) #@pc?.removeStream?(@lstream) if stream.getAudioTracks? for track in stream.getAudioTracks() if stream.getVideoTracks? for track in stream.getVideoTracks()