webrtc-rails 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/assets/javascripts/webrtc_rails/main.js.coffee +24 -24
- data/lib/generators/webrtc_rails/install/templates/webrtc_rails.rb +1 -1
- data/lib/webrtc_rails/configuration.rb +2 -2
- data/lib/webrtc_rails/daemon.rb +28 -28
- data/lib/webrtc_rails/daemon_delegate.rb +4 -4
- data/lib/webrtc_rails/server_message.rb +2 -2
- data/lib/webrtc_rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 419827da35a81ffe543136d565e7088ba90a3880
|
4
|
+
data.tar.gz: de113a1dcd30ce90c3b4b3fefcfc9ed87943a92f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a71896b612d7dc16e3dd664f7ecc2a3e8446d9a63e6aaa91415d6e5e43fb73552e649c25e267a6d65bb0270c1407fa3f529ecf813e78ae6dde38cb72e6daaaae
|
7
|
+
data.tar.gz: abbba85d848e9cd5bfdf9bed4de669acc63c9e3cd246f468f054d8c973916e42adf42d0e54d0dae82c4a66870792c88ecf90c68a3bb64a868b060ba4f3f2ecf5
|
@@ -3,19 +3,19 @@ class @WebRTC
|
|
3
3
|
@TIMEOUT: 1
|
4
4
|
@CALLING: 2
|
5
5
|
|
6
|
-
|
6
|
+
myUserIdentifier: null
|
7
7
|
|
8
8
|
onWebSocketConnected: ->
|
9
9
|
onWebSocketReconnectingStarted: ->
|
10
10
|
onWebSocketReconnected: ->
|
11
|
-
onWebRTCCall: (
|
11
|
+
onWebRTCCall: (remoteUserIdentifier) ->
|
12
12
|
onWebRTCConnected: ->
|
13
13
|
onWebRTCReconnectingStarted: ->
|
14
14
|
onWebRTCReconnected: ->
|
15
15
|
onWebRTCHangedUp: ->
|
16
16
|
onWebRTCConnectFailed: (reason) ->
|
17
17
|
onServerMessage: (message) ->
|
18
|
-
onUserMessage: (
|
18
|
+
onUserMessage: (sentUserIdentifier, event, message) ->
|
19
19
|
|
20
20
|
constructor: (url, userToken, localOutput, remoteOutput) ->
|
21
21
|
@localOutput = if localOutput? then (localOutput[0] || localOutput) else null
|
@@ -24,17 +24,17 @@ class @WebRTC
|
|
24
24
|
@_webSocketInitialize(url, userToken)
|
25
25
|
@_addNetworkEventListener()
|
26
26
|
|
27
|
-
|
27
|
+
call: (remoteUserIdentifier) ->
|
28
28
|
if @_webRTCReconnecting && @_hangedUp
|
29
29
|
@_webRTCReconnecting = false
|
30
30
|
return
|
31
31
|
|
32
32
|
@_isCaller = true
|
33
|
-
@
|
33
|
+
@_remoteUserIdentifier = remoteUserIdentifier
|
34
34
|
if !@_peerStarted && @_localStream
|
35
35
|
@_sendMessage(
|
36
36
|
type: 'call'
|
37
|
-
|
37
|
+
remoteUserIdentifier: @myUserIdentifier
|
38
38
|
reconnect: @_webRTCReconnecting
|
39
39
|
)
|
40
40
|
@_callAnswerReceived = false
|
@@ -42,7 +42,7 @@ class @WebRTC
|
|
42
42
|
=>
|
43
43
|
unless @_callAnswerReceived
|
44
44
|
if @_webRTCReconnecting
|
45
|
-
@connect(
|
45
|
+
@connect(remoteUserIdentifier)
|
46
46
|
else
|
47
47
|
@onWebRTCConnectFailed(WebRTC.TIMEOUT)
|
48
48
|
5000
|
@@ -55,9 +55,9 @@ class @WebRTC
|
|
55
55
|
@_sendOffer()
|
56
56
|
@_peerStarted = true
|
57
57
|
|
58
|
-
sendUserMessage: (
|
58
|
+
sendUserMessage: (userIdentifier, event, message) ->
|
59
59
|
@_sendValue('userMessage',
|
60
|
-
|
60
|
+
userIdentifier: String(userIdentifier)
|
61
61
|
event: event
|
62
62
|
message: message
|
63
63
|
)
|
@@ -94,7 +94,7 @@ class @WebRTC
|
|
94
94
|
@_sendValue('setMyToken')
|
95
95
|
if @_wantWebRTCReconnecting
|
96
96
|
@_wantWebRTCReconnecting = false
|
97
|
-
@connect(@
|
97
|
+
@connect(@_remoteUserIdentifier)
|
98
98
|
|
99
99
|
@_webSocket.onclose = (event) =>
|
100
100
|
unless @_isWebSocketReconnectingStarted
|
@@ -106,16 +106,16 @@ class @WebRTC
|
|
106
106
|
event = JSON.parse(data.data)
|
107
107
|
eventType = event['type']
|
108
108
|
if eventType == 'userMessage'
|
109
|
-
@onUserMessage(event['
|
109
|
+
@onUserMessage(event['remoteUserIdentifier'], event['event'], event['message'])
|
110
110
|
return
|
111
111
|
|
112
|
-
if eventType != '
|
113
|
-
if @
|
112
|
+
if eventType != 'myUserIdentifier' && eventType != 'call' && eventType != 'webSocketReconnected'
|
113
|
+
if @_remoteUserIdentifier != event['remoteUserIdentifier']
|
114
114
|
return
|
115
115
|
|
116
116
|
switch eventType
|
117
|
-
when '
|
118
|
-
@
|
117
|
+
when 'myUserIdentifier'
|
118
|
+
@myUserIdentifier = event['myUserIdentifier']
|
119
119
|
if @_webSocketConnected
|
120
120
|
@onWebSocketReconnected()
|
121
121
|
if @_hangedUp
|
@@ -126,8 +126,8 @@ class @WebRTC
|
|
126
126
|
@onWebSocketConnected()
|
127
127
|
@_webSocketConnected = true
|
128
128
|
when 'webSocketReconnected'
|
129
|
-
if @_hangedUp || @
|
130
|
-
@_sendMessageToOther(type: 'hangUp', event['
|
129
|
+
if @_hangedUp || @_remoteUserIdentifier != event['remoteUserIdentifier']
|
130
|
+
@_sendMessageToOther(type: 'hangUp', event['remoteUserIdentifier'])
|
131
131
|
when 'callFailed'
|
132
132
|
@_callAnswerReceived = true
|
133
133
|
@onWebRTCConnectFailed(event['reason'] || WebRTC.UNKNOWN)
|
@@ -136,12 +136,12 @@ class @WebRTC
|
|
136
136
|
message =
|
137
137
|
type: 'callFailed'
|
138
138
|
reason: WebRTC.CALLING
|
139
|
-
@_sendMessageToOther(message, event['
|
139
|
+
@_sendMessageToOther(message, event['remoteUserIdentifier'])
|
140
140
|
else if event['reconnect'] && @_hangedUp
|
141
141
|
@_sendMessage(type: 'hangUp')
|
142
142
|
else
|
143
|
-
@
|
144
|
-
@onWebRTCCall(@
|
143
|
+
@_remoteUserIdentifier = event['remoteUserIdentifier']
|
144
|
+
@onWebRTCCall(@_remoteUserIdentifier)
|
145
145
|
when 'hangUp'
|
146
146
|
@_callAnswerReceived = true
|
147
147
|
@_hangUp()
|
@@ -186,14 +186,14 @@ class @WebRTC
|
|
186
186
|
value: value
|
187
187
|
))
|
188
188
|
|
189
|
-
_sendMessageToOther: (message,
|
189
|
+
_sendMessageToOther: (message, userIdentifier) ->
|
190
190
|
@_sendValue('sendMessage',
|
191
|
-
|
191
|
+
userIdentifier: String(userIdentifier)
|
192
192
|
message: message
|
193
193
|
)
|
194
194
|
|
195
195
|
_sendMessage: (message) ->
|
196
|
-
@_sendMessageToOther(message, @
|
196
|
+
@_sendMessageToOther(message, @_remoteUserIdentifier)
|
197
197
|
|
198
198
|
_startOutput: (localOutput) ->
|
199
199
|
isVideo = (@localOutput? && @localOutput.tagName.toUpperCase() == 'VIDEO')
|
@@ -282,7 +282,7 @@ class @WebRTC
|
|
282
282
|
if @_isCaller
|
283
283
|
@_webRTCReconnecting = true
|
284
284
|
if @_webSocket.readyState == WebSocket.OPEN
|
285
|
-
@connect(@
|
285
|
+
@connect(@_remoteUserIdentifier)
|
286
286
|
else
|
287
287
|
@_wantWebRTCReconnecting = true
|
288
288
|
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module WebrtcRails
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :user_model_class, :fetch_user_by_token_method, :
|
3
|
+
attr_accessor :user_model_class, :fetch_user_by_token_method, :user_identifier, :daemon_delegate
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
@user_model_class = 'User'
|
7
7
|
@fetch_user_by_token_method = :fetch_by_token
|
8
|
-
@
|
8
|
+
@user_identifier = :id
|
9
9
|
@daemon_delegate = 'WebrtcRails::DaemonDelegate'
|
10
10
|
end
|
11
11
|
end
|
data/lib/webrtc_rails/daemon.rb
CHANGED
@@ -9,7 +9,7 @@ module WebrtcRails
|
|
9
9
|
@config = WebrtcRails.configuration
|
10
10
|
@user_class = @config.user_model_class.constantize
|
11
11
|
@fetch_user_by_token_method = @config.fetch_user_by_token_method
|
12
|
-
@
|
12
|
+
@user_identifier = @config.user_identifier
|
13
13
|
@daemon_delegate = @config.daemon_delegate.constantize.new
|
14
14
|
end
|
15
15
|
|
@@ -20,10 +20,10 @@ module WebrtcRails
|
|
20
20
|
pubsub.subscribe('webrtc-rails')
|
21
21
|
pubsub.on(:message) do |channel, message|
|
22
22
|
data = JSON.parse(message, {symbolize_names: true})
|
23
|
-
|
23
|
+
user_identifier = data[:user_identifier].to_s
|
24
24
|
message = data[:message]
|
25
|
-
if @websockets.key?(
|
26
|
-
for ws in @websockets[
|
25
|
+
if @websockets.key?(user_identifier)
|
26
|
+
for ws in @websockets[user_identifier]
|
27
27
|
send_data = {
|
28
28
|
type: 'serverMessage',
|
29
29
|
message: message
|
@@ -34,13 +34,13 @@ module WebrtcRails
|
|
34
34
|
end
|
35
35
|
|
36
36
|
EM::WebSocket.run(host: 'localhost', port: 3001) do |websocket|
|
37
|
-
|
37
|
+
my_user_identifier = nil
|
38
38
|
|
39
39
|
websocket.onclose do
|
40
|
-
if
|
41
|
-
if @websockets[
|
42
|
-
@websockets[
|
43
|
-
@daemon_delegate.onWebSocketDisconnected(
|
40
|
+
if my_user_identifier.present?
|
41
|
+
if @websockets[my_user_identifier].present?
|
42
|
+
@websockets[my_user_identifier].delete(websocket)
|
43
|
+
@daemon_delegate.onWebSocketDisconnected(my_user_identifier)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
@@ -51,46 +51,46 @@ module WebrtcRails
|
|
51
51
|
token = data[:token]
|
52
52
|
if token.present?
|
53
53
|
user = @user_class.send(@fetch_user_by_token_method, token)
|
54
|
-
|
55
|
-
if
|
54
|
+
my_user_identifier = user ? user.send(@user_identifier).to_s : nil
|
55
|
+
if my_user_identifier.present?
|
56
56
|
case data[:event]
|
57
57
|
when 'userMessage'
|
58
|
-
|
58
|
+
user_identifier = data[:value][:userIdentifier]
|
59
59
|
event = data[:value][:event]
|
60
60
|
message = data[:value][:message]
|
61
|
-
if @daemon_delegate.onWantSendUserMessage(
|
61
|
+
if @daemon_delegate.onWantSendUserMessage(my_user_identifier, user_identifier, event, message)
|
62
62
|
message = {
|
63
63
|
type: 'userMessage',
|
64
|
-
|
64
|
+
remoteUserIdentifier: my_user_identifier,
|
65
65
|
event: event,
|
66
66
|
message: message
|
67
67
|
}
|
68
|
-
sendMessage(
|
68
|
+
sendMessage(user_identifier, message)
|
69
69
|
end
|
70
70
|
when 'setMyToken'
|
71
|
-
@websockets[
|
72
|
-
@websockets[
|
71
|
+
@websockets[my_user_identifier] ||= []
|
72
|
+
@websockets[my_user_identifier].push(websocket)
|
73
73
|
message = {
|
74
|
-
type: '
|
75
|
-
|
74
|
+
type: 'myUserIdentifier',
|
75
|
+
myUserIdentifier: my_user_identifier
|
76
76
|
}
|
77
|
-
@daemon_delegate.onWebSocketConnected(
|
77
|
+
@daemon_delegate.onWebSocketConnected(my_user_identifier)
|
78
78
|
websocket.send JSON.generate(message)
|
79
79
|
when 'sendMessage'
|
80
|
-
|
80
|
+
user_identifier = data[:value][:userIdentifier]
|
81
81
|
type = data[:value][:message][:type]
|
82
82
|
allow_types = %w/call hangUp offer answer candidate callFailed userMessage webSocketReconnected/
|
83
|
-
if @websockets.key?(
|
84
|
-
if type != 'call' || @daemon_delegate.onWantCall(
|
83
|
+
if @websockets.key?(user_identifier) && type.present? && allow_types.include?(type)
|
84
|
+
if type != 'call' || @daemon_delegate.onWantCall(my_user_identifier, user_identifier)
|
85
85
|
message = data[:value][:message]
|
86
|
-
message[:
|
87
|
-
sendMessage(
|
86
|
+
message[:remoteUserIdentifier] = my_user_identifier
|
87
|
+
sendMessage(user_identifier, message)
|
88
88
|
end
|
89
89
|
else
|
90
90
|
message = {
|
91
91
|
type: 'callFailed',
|
92
92
|
reason: 0,
|
93
|
-
|
93
|
+
remoteUserIdentifier: user_identifier
|
94
94
|
}
|
95
95
|
websocket.send JSON.generate(message)
|
96
96
|
end
|
@@ -105,8 +105,8 @@ module WebrtcRails
|
|
105
105
|
|
106
106
|
private
|
107
107
|
|
108
|
-
def sendMessage(
|
109
|
-
for ws in @websockets[
|
108
|
+
def sendMessage(user_identifier, message)
|
109
|
+
for ws in @websockets[user_identifier]
|
110
110
|
ws.send JSON.generate(message)
|
111
111
|
end
|
112
112
|
end
|
@@ -1,18 +1,18 @@
|
|
1
1
|
module WebrtcRails
|
2
2
|
class DaemonDelegate
|
3
|
-
def onWebSocketConnected(
|
3
|
+
def onWebSocketConnected(user_identifier)
|
4
4
|
|
5
5
|
end
|
6
6
|
|
7
|
-
def onWebSocketDisconnected(
|
7
|
+
def onWebSocketDisconnected(user_identifier)
|
8
8
|
|
9
9
|
end
|
10
10
|
|
11
|
-
def onWantCall(
|
11
|
+
def onWantCall(sent_user_identifier, will_receive_user_identifier)
|
12
12
|
true
|
13
13
|
end
|
14
14
|
|
15
|
-
def onWantSendUserMessage(
|
15
|
+
def onWantSendUserMessage(sent_user_identifier, will_receive_user_identifier, event, message)
|
16
16
|
true
|
17
17
|
end
|
18
18
|
end
|
data/lib/webrtc_rails/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webrtc-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Koji Murata
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-11-
|
11
|
+
date: 2015-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: em-websocket
|