Class: SelfSDK::Services::Voice

Inherits:
Object
  • Object
show all
Defined in:
lib/services/voice.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(messaging) ⇒ Voice

Returns a new instance of Voice.



16
17
18
# File 'lib/services/voice.rb', line 16

def initialize(messaging)
  @messaging = messaging
end

Instance Attribute Details

#app_idObject

Returns the value of attribute app_id.



14
15
16
# File 'lib/services/voice.rb', line 14

def app_id
  @app_id
end

Instance Method Details

#accept(recipient, cid, call_id, peer_info) ⇒ Object

Sends a chat.voice.accept message accepting a specific call.



59
60
61
62
63
64
65
66
67
# File 'lib/services/voice.rb', line 59

def accept(recipient, cid, call_id, peer_info)
  payload = {
    typ: SelfSDK::Messages::VoiceAccept::MSG_TYPE,
    cid: cid,
    call_id: call_id,
    peer_info: peer_info,
  }
  send([recipient], payload)
end

#busy(recipient, cid, call_id) ⇒ Object

Sends a chat.voice.busy message finishing the call.



102
103
104
105
106
107
# File 'lib/services/voice.rb', line 102

def busy(recipient, cid, call_id)
  send([recipient],
       typ: SelfSDK::Messages::VoiceBusy::MSG_TYPE,
       cid: cid,
       call_id: call_id)
end

#on_accept(&block) ⇒ Object

Subscribes to chat.voice.accept messages.



70
71
72
73
74
75
76
77
78
# File 'lib/services/voice.rb', line 70

def on_accept(&block)
  @messaging.subscribe :voice_accept do |msg|
    call(block,
         msg.payload[:iss],
         cid: msg.payload[:cid],
         call_id: msg.payload[:call_id],
         peer_info: msg.payload[:peer_info])
  end
end

#on_busy(&block) ⇒ Object

Subscribes to chat.voice.busy messages.



110
111
112
113
114
115
116
117
118
# File 'lib/services/voice.rb', line 110

def on_busy(&block)
  @messaging.subscribe :voice_busy do |msg|
    call(block,
         msg.payload[:iss],
         cid: msg.payload[:cid],
         call_id: msg.payload[:call_id],
         peer_info: msg.payload[:peer_info])
  end
end

#on_setup(&block) ⇒ Object

Subscribes to chat.voice.setup messages.



30
31
32
33
34
# File 'lib/services/voice.rb', line 30

def on_setup(&block)
  @messaging.subscribe :voice_setup do |msg|
    call(block, msg.payload[:iss], msg.payload[:cid], msg.payload[:data])
  end
end

#on_start(&block) ⇒ Object

Subscribes to chat.voice.start messages.



47
48
49
50
51
52
53
54
55
56
# File 'lib/services/voice.rb', line 47

def on_start(&block)
  @messaging.subscribe :voice_start do |msg|
    call(block,
         msg.payload[:iss],
         cid: msg.payload[:cid],
         call_id: msg.payload[:call_id],
         peer_info: msg.payload[:peer_info],
         data: msg.payload[:data])
  end
end

#on_stop(&block) ⇒ Object

Subscribes to chat.voice.stop messages.



91
92
93
94
95
96
97
98
99
# File 'lib/services/voice.rb', line 91

def on_stop(&block)
  @messaging.subscribe :voice_stop do |msg|
    call(block,
         msg.payload[:iss],
         cid: msg.payload[:cid],
         call_id: msg.payload[:call_id],
         peer_info: msg.payload[:peer_info])
  end
end

#on_summary(&block) ⇒ Object

Subscribes to chat.voice.summary messages.



129
130
131
132
133
134
135
136
137
# File 'lib/services/voice.rb', line 129

def on_summary(&block)
  @messaging.subscribe :voice_summary do |msg|
    call(block,
         msg.payload[:iss],
         cid: msg.payload[:cid],
         call_id: msg.payload[:call_id],
         peer_info: msg.payload[:peer_info])
  end
end

#setup(recipient, name, cid) ⇒ Object

Sends a chat.voice.setup message to setup a delegated call.



21
22
23
24
25
26
27
# File 'lib/services/voice.rb', line 21

def setup(recipient, name, cid)
  payload = { typ: SelfSDK::Messages::VoiceSetup::MSG_TYPE }
  payload[:cid] = cid
  payload[:data] = { name: name }

  send([recipient], payload)
end

#start(recipient, cid, call_id, peer_info, data) ⇒ Object

Sends a chat.voice.start message with the details for starting a call.



37
38
39
40
41
42
43
44
# File 'lib/services/voice.rb', line 37

def start(recipient, cid, call_id, peer_info, data)
  send([recipient],
       typ: SelfSDK::Messages::VoiceStart::MSG_TYPE,
       cid: cid,
       call_id: call_id,
       peer_info: peer_info,
       data: data)
end

#stop(recipient, cid, call_id) ⇒ Object

Sends a chat.voice.accept message finishing the call.



81
82
83
84
85
86
87
88
# File 'lib/services/voice.rb', line 81

def stop(recipient, cid, call_id)
  payload = {
    typ: SelfSDK::Messages::VoiceStop::MSG_TYPE,
    cid: cid,
    call_id: call_id,
  }
  send([recipient], payload)
end

#summary(recipient, cid, call_id) ⇒ Object

Sends a chat.voice.summary message Sending details about the call.



121
122
123
124
125
126
# File 'lib/services/voice.rb', line 121

def summary(recipient, cid, call_id)
  send([recipient],
       typ: SelfSDK::Messages::VoiceSummary::MSG_TYPE,
       cid: cid,
       call_id: call_id)
end