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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5acc76973316c7f4862f065ff04f8e22e9b447f2
4
- data.tar.gz: b4d38046a0464556fefabfc6bad6e4137c3d564c
3
+ metadata.gz: 419827da35a81ffe543136d565e7088ba90a3880
4
+ data.tar.gz: de113a1dcd30ce90c3b4b3fefcfc9ed87943a92f
5
5
  SHA512:
6
- metadata.gz: 92f150f4342830813fe048708af6e61c1863db65de7c380ad2944cb7b6d2c304e02899b131c88af0593ed6205f33ade9c39a7f52f5047df7e9ca7f9551e78376
7
- data.tar.gz: 7613f98f970fbf2a5a9a18fa1cbf0166988471ba909dcede6512eda27a7ebfc95c6cb9270993ec40dee4c32b98f047cdc5737480465ed6416cdf6f14e655eaf4
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
- myUserID: null
6
+ myUserIdentifier: null
7
7
 
8
8
  onWebSocketConnected: ->
9
9
  onWebSocketReconnectingStarted: ->
10
10
  onWebSocketReconnected: ->
11
- onWebRTCCall: (remoteUserID) ->
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: (sentUserID, event, message) ->
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
- connect: (remoteUserID) ->
27
+ call: (remoteUserIdentifier) ->
28
28
  if @_webRTCReconnecting && @_hangedUp
29
29
  @_webRTCReconnecting = false
30
30
  return
31
31
 
32
32
  @_isCaller = true
33
- @_remoteUserID = remoteUserID
33
+ @_remoteUserIdentifier = remoteUserIdentifier
34
34
  if !@_peerStarted && @_localStream
35
35
  @_sendMessage(
36
36
  type: 'call'
37
- remoteUserID: @myUserID
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(remoteUserID)
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: (userID, event, message) ->
58
+ sendUserMessage: (userIdentifier, event, message) ->
59
59
  @_sendValue('userMessage',
60
- userID: String(userID)
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(@_remoteUserID)
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['remoteUserID'], event['event'], event['message'])
109
+ @onUserMessage(event['remoteUserIdentifier'], event['event'], event['message'])
110
110
  return
111
111
 
112
- if eventType != 'myUserID' && eventType != 'call' && eventType != 'webSocketReconnected'
113
- if @_remoteUserID != event['remoteUserID']
112
+ if eventType != 'myUserIdentifier' && eventType != 'call' && eventType != 'webSocketReconnected'
113
+ if @_remoteUserIdentifier != event['remoteUserIdentifier']
114
114
  return
115
115
 
116
116
  switch eventType
117
- when 'myUserID'
118
- @myUserID = event['myUserID']
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 || @_remoteUserID != event['remoteUserID']
130
- @_sendMessageToOther(type: 'hangUp', event['remoteUserID'])
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['remoteUserID'])
139
+ @_sendMessageToOther(message, event['remoteUserIdentifier'])
140
140
  else if event['reconnect'] && @_hangedUp
141
141
  @_sendMessage(type: 'hangUp')
142
142
  else
143
- @_remoteUserID = event['remoteUserID']
144
- @onWebRTCCall(@_remoteUserID)
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, userID) ->
189
+ _sendMessageToOther: (message, userIdentifier) ->
190
190
  @_sendValue('sendMessage',
191
- userID: String(userID)
191
+ userIdentifier: String(userIdentifier)
192
192
  message: message
193
193
  )
194
194
 
195
195
  _sendMessage: (message) ->
196
- @_sendMessageToOther(message, @_remoteUserID)
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(@_remoteUserID)
285
+ @connect(@_remoteUserIdentifier)
286
286
  else
287
287
  @_wantWebRTCReconnecting = true
288
288
 
@@ -1,6 +1,6 @@
1
1
  WebrtcRails.configure do |config|
2
2
  # config.user_model_class = 'User'
3
3
  # config.fetch_user_by_token_method = :fetch_by_token
4
- # config.user_id = :id
4
+ # config.user_identifier = :id
5
5
  # config.daemon_delegate = 'WebrtcRails::DaemonDelegate'
6
6
  end
@@ -1,11 +1,11 @@
1
1
  module WebrtcRails
2
2
  class Configuration
3
- attr_accessor :user_model_class, :fetch_user_by_token_method, :user_id, :daemon_delegate
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
- @user_id = :id
8
+ @user_identifier = :id
9
9
  @daemon_delegate = 'WebrtcRails::DaemonDelegate'
10
10
  end
11
11
  end
@@ -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
- @user_id = @config.user_id
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
- user_id = data[:user_id].to_s
23
+ user_identifier = data[:user_identifier].to_s
24
24
  message = data[:message]
25
- if @websockets.key?(user_id)
26
- for ws in @websockets[user_id]
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
- my_user_id = nil
37
+ my_user_identifier = nil
38
38
 
39
39
  websocket.onclose do
40
- if my_user_id.present?
41
- if @websockets[my_user_id].present?
42
- @websockets[my_user_id].delete(websocket)
43
- @daemon_delegate.onWebSocketDisconnected(my_user_id)
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
- my_user_id = user ? user.send(@user_id).to_s : nil
55
- if my_user_id.present?
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
- user_id = data[:value][:userID]
58
+ user_identifier = data[:value][:userIdentifier]
59
59
  event = data[:value][:event]
60
60
  message = data[:value][:message]
61
- if @daemon_delegate.onWantSendUserMessage(my_user_id, user_id, event, message)
61
+ if @daemon_delegate.onWantSendUserMessage(my_user_identifier, user_identifier, event, message)
62
62
  message = {
63
63
  type: 'userMessage',
64
- remoteUserID: my_user_id,
64
+ remoteUserIdentifier: my_user_identifier,
65
65
  event: event,
66
66
  message: message
67
67
  }
68
- sendMessage(user_id, message)
68
+ sendMessage(user_identifier, message)
69
69
  end
70
70
  when 'setMyToken'
71
- @websockets[my_user_id] ||= []
72
- @websockets[my_user_id].push(websocket)
71
+ @websockets[my_user_identifier] ||= []
72
+ @websockets[my_user_identifier].push(websocket)
73
73
  message = {
74
- type: 'myUserID',
75
- myUserID: my_user_id
74
+ type: 'myUserIdentifier',
75
+ myUserIdentifier: my_user_identifier
76
76
  }
77
- @daemon_delegate.onWebSocketConnected(my_user_id)
77
+ @daemon_delegate.onWebSocketConnected(my_user_identifier)
78
78
  websocket.send JSON.generate(message)
79
79
  when 'sendMessage'
80
- user_id = data[:value][:userID]
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?(user_id) && type.present? && allow_types.include?(type)
84
- if type != 'call' || @daemon_delegate.onWantCall(my_user_id, user_id)
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[:remoteUserID] = my_user_id
87
- sendMessage(user_id, message)
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
- remoteUserID: user_id
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(user_id, message)
109
- for ws in @websockets[user_id]
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(user_id)
3
+ def onWebSocketConnected(user_identifier)
4
4
 
5
5
  end
6
6
 
7
- def onWebSocketDisconnected(user_id)
7
+ def onWebSocketDisconnected(user_identifier)
8
8
 
9
9
  end
10
10
 
11
- def onWantCall(sent_user_id, will_receive_user_id)
11
+ def onWantCall(sent_user_identifier, will_receive_user_identifier)
12
12
  true
13
13
  end
14
14
 
15
- def onWantSendUserMessage(sent_user_id, will_receive_user_id, event, message)
15
+ def onWantSendUserMessage(sent_user_identifier, will_receive_user_identifier, event, message)
16
16
  true
17
17
  end
18
18
  end
@@ -3,9 +3,9 @@ require 'json'
3
3
 
4
4
  module WebrtcRails
5
5
  module ServerMessage
6
- def send(user_id, message)
6
+ def send(user_identifier, message)
7
7
  data = {
8
- user_id: user_id,
8
+ user_identifier: user_identifier,
9
9
  message: message,
10
10
  }
11
11
  redis = Redis.new
@@ -1,3 +1,3 @@
1
1
  module WebrtcRails
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
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.1
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-26 00:00:00.000000000 Z
11
+ date: 2015-11-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: em-websocket