-
Notifications
You must be signed in to change notification settings - Fork 7
/
CineAPIBridge.coffee
110 lines (87 loc) · 3.21 KB
/
CineAPIBridge.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
CineActionCreators = require('../actions/CineActionCreators')
CineAPIBridge =
_handleOutgoingCall: (err, data)->
callObj = data.call
CineActionCreators.currentCall(callObj)
callObj.on 'call-reject', ->
CineActionCreators.callRejected(callObj)
joinRoom: (name)->
CineIOPeer.join(name)
leaveRoom: (name)->
CineIOPeer.leave(name)
identify: (data)->
CineIOPeer.identify(data.identity, data.timestamp, data.signature)
call: (identity, options={})->
if options.call
options.call.invite(identity)
else if options.room
CineIOPeer.call identity, options.room, CineAPIBridge._handleOutgoingCall
# unnecessary else, but helpful verbosity
else
CineIOPeer.call identity, CineAPIBridge._handleOutgoingCall
sendDataToAll: (data)->
console.log("CineAPIBridge sendDataToAll", data)
CineIOPeer.sendDataToAll(data)
startCameraAndMicrophone: ->
console.log("CineAPIBridge startCameraAndMicrophone")
CineIOPeer.startCameraAndMicrophone()
muteAudio: ->
console.log("CineAPIBridge muteAudio")
CineIOPeer.stopMicrophone()
unmuteAudio: ->
console.log("CineAPIBridge unmuteAudio")
CineIOPeer.startMicrophone()
muteVideo: ->
console.log("CineAPIBridge muteVideo")
CineIOPeer.stopCamera()
startScreenShare: ->
console.log("CineAPIBridge startScreenShare")
CineIOPeer.startScreenShare()
stopScreenShare: ->
console.log("CineAPIBridge stopScreenShare")
CineIOPeer.stopScreenShare()
unmuteVideo: ->
console.log("CineAPIBridge unmuteVideo")
CineIOPeer.startCamera()
init: ->
CineIOPeer.on 'media-rejected', (data)->
alert('Permission denied.')
CineIOPeer.on 'extension-required', (data)->
CineActionCreators.showInstallExtension(data.url, data.type)
CineIOPeer.on 'error', (err)->
if (typeof(err.support) != "undefined" && !err.support)
alert("This browser does not support WebRTC.")
else if (err.msg)
alert(err.msg)
CineIOPeer.on 'call', (data)->
console.log("NEW CALL", data)
callObj = data.call
CineActionCreators.newCall(callObj)
callObj.on 'call-cancel', ->
CineActionCreators.callCancelled(callObj)
CineIOPeer.on 'peer-data', (data)->
console.log("GOT DATA CALL", data)
CineActionCreators.gotPeerData(data)
# data.call.answer()
CineIOPeer.on 'media-added', (data)->
console.log("Media added")
if data.local
if data.type == 'camera'
CineActionCreators.localWebcamStarted(data.videoElement)
else if data.type == 'screen'
CineActionCreators.localScreenShareStarted(data.videoElement)
else
console.log("REMOTE PEERRRR")
CineActionCreators.newPeer(data.videoElement)
CineIOPeer.on 'media-removed', (data)->
console.log("Media removed")
if data.local
if data.type == 'camera'
CineActionCreators.localWebcamRemoved(data.videoElement)
else if data.type == 'screen'
CineActionCreators.localScreenShareRemoved(data.videoElement)
else
console.log("REMOTE PEERRRR")
CineActionCreators.peerLeft(data.videoElement)
CineAPIBridge.startCameraAndMicrophone()
module.exports = CineAPIBridge