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.



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

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.



99
100
101
102
103
104
# File 'lib/services/voice.rb', line 99

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.



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

def on_accept(&block)
  @messaging.subscribe :voice_accept do |msg|
    block.call(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.



107
108
109
110
111
112
113
114
# File 'lib/services/voice.rb', line 107

def on_busy(&block)
  @messaging.subscribe :voice_busy do |msg|
    block.call(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|
    block.call(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
# File 'lib/services/voice.rb', line 47

def on_start(&block)
  @messaging.subscribe :voice_start do |msg|
    block.call(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.



89
90
91
92
93
94
95
96
# File 'lib/services/voice.rb', line 89

def on_stop(&block)
  @messaging.subscribe :voice_stop do |msg|
    block.call(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.



125
126
127
128
129
130
131
132
# File 'lib/services/voice.rb', line 125

def on_summary(&block)
  @messaging.subscribe :voice_summary do |msg|
    block.call(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.



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

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.



117
118
119
120
121
122
# File 'lib/services/voice.rb', line 117

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