selfsdk 0.0.203 → 0.0.204

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/services/voice.rb +147 -0
  3. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea79de24bb9968fdd994ea934e93665edbd640ab6eb69b129a692f3eee92ae90
4
- data.tar.gz: 94bef0e9ad11a2bc9362d02105ef023ec7e635ae253d3b653c263d1130d21e52
3
+ metadata.gz: e43ffd18c6b77a9d2c4be2a20e99f634f2c4c4b16e5192ef095ba728fedf04c3
4
+ data.tar.gz: 07a2dd57e3d9dc547e56357043656f86e8018022a156c506cfecf040d8a6d1ef
5
5
  SHA512:
6
- metadata.gz: b72a3aa8ba3d723404c59854a2d2b1fd96ab5954506f064fc1b34459c5b31cec20551664fd7133929777be3d2def925a2d3a8a991de9c2b76ab2f725a3572335
7
- data.tar.gz: 3ef093c5fb94a36cb91ef2576eb5b38f9b401694d8464f35c588f6b45e29860251383fe697d655c66c5af9135b0af759bc6d82a5dea4363b48e1110245b9ad27
6
+ metadata.gz: bc3ef76d0c8556b4a569ee7d0e8eacc9d35d519dd0dd2612155a622db1affe85ea393b47963c8b1eb4e47cb619a72b4d6e2976dfd3cc57690d75ed6846868e34
7
+ data.tar.gz: beea6022c1e6510fea1e6a293d678af1d9b85e892a7e654327dbecd93150f616dd812ec52c9ea7290a9ef74f9fd0f65225c607610c528b66b8b20c9cf9f3a444
@@ -0,0 +1,147 @@
1
+ # Copyright 2020 Self Group Ltd. All Rights Reserved.
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'self_crypto'
6
+ require_relative '../chat/file_object'
7
+ require_relative '../chat/group'
8
+ require_relative '../chat/message'
9
+ require_relative "../messages/connection_request"
10
+
11
+ module SelfSDK
12
+ module Services
13
+ class Voice
14
+ attr_accessor :app_id
15
+
16
+ def initialize(messaging)
17
+ @messaging = messaging
18
+ end
19
+
20
+ # Sends a chat.voice.setup message to setup a delegated call.
21
+ def setup(recipient, name, cid)
22
+ payload = { typ: SelfSDK::Messages::VoiceSetup::MSG_TYPE }
23
+ payload[:cid] = cid
24
+ payload[:data] = { name: name }
25
+
26
+ send([recipient], payload)
27
+ end
28
+
29
+ # Subscribes to chat.voice.setup messages.
30
+ def on_setup(&block)
31
+ @messaging.subscribe :voice_setup do |msg|
32
+ block.call(msg.payload[:iss], msg.payload[:cid], msg.payload[:data])
33
+ end
34
+ end
35
+
36
+ # Sends a chat.voice.start message with the details for starting a call.
37
+ def start(recipient, cid, call_id, peer_info, data)
38
+ send([recipient],
39
+ typ: SelfSDK::Messages::VoiceStart::MSG_TYPE,
40
+ cid: cid,
41
+ call_id: call_id,
42
+ peer_info: peer_info,
43
+ data: data)
44
+ end
45
+
46
+ # Subscribes to chat.voice.start messages.
47
+ def on_start(&block)
48
+ @messaging.subscribe :voice_start do |msg|
49
+ block.call(msg.payload[:iss],
50
+ cid: msg.payload[:cid],
51
+ call_id: msg.payload[:call_id],
52
+ peer_info: msg.payload[:peer_info],
53
+ data: msg.payload[:data])
54
+ end
55
+ end
56
+
57
+ # Sends a chat.voice.accept message accepting a specific call.
58
+ def accept(recipient, cid, call_id, peer_info)
59
+ payload = {
60
+ typ: SelfSDK::Messages::VoiceAccept::MSG_TYPE,
61
+ cid: cid,
62
+ call_id: call_id,
63
+ peer_info: peer_info,
64
+ }
65
+ send([recipient], payload)
66
+ end
67
+
68
+ # Subscribes to chat.voice.accept messages.
69
+ def on_accept(&block)
70
+ @messaging.subscribe :voice_accept do |msg|
71
+ block.call(msg.payload[:iss],
72
+ cid: msg.payload[:cid],
73
+ call_id: msg.payload[:call_id],
74
+ peer_info: msg.payload[:peer_info])
75
+ end
76
+ end
77
+
78
+ # Sends a chat.voice.accept message finishing the call.
79
+ def stop(recipient, cid, call_id)
80
+ payload = {
81
+ typ: SelfSDK::Messages::VoiceStop::MSG_TYPE,
82
+ cid: cid,
83
+ call_id: call_id,
84
+ }
85
+ send([recipient], payload)
86
+ end
87
+
88
+ # Subscribes to chat.voice.stop messages.
89
+ def on_stop(&block)
90
+ @messaging.subscribe :voice_stop do |msg|
91
+ block.call(msg.payload[:iss],
92
+ cid: msg.payload[:cid],
93
+ call_id: msg.payload[:call_id],
94
+ peer_info: msg.payload[:peer_info])
95
+ end
96
+ end
97
+
98
+ # Sends a chat.voice.busy message finishing the call.
99
+ def busy(recipient, cid, call_id)
100
+ send([recipient],
101
+ typ: SelfSDK::Messages::VoiceBusy::MSG_TYPE,
102
+ cid: cid,
103
+ call_id: call_id)
104
+ end
105
+
106
+ # Subscribes to chat.voice.busy messages.
107
+ def on_busy(&block)
108
+ @messaging.subscribe :voice_busy do |msg|
109
+ block.call(msg.payload[:iss],
110
+ cid: msg.payload[:cid],
111
+ call_id: msg.payload[:call_id],
112
+ peer_info: msg.payload[:peer_info])
113
+ end
114
+ end
115
+
116
+ # Sends a chat.voice.summary message Sending details about the call.
117
+ def summary(recipient, cid, call_id)
118
+ send([recipient],
119
+ typ: SelfSDK::Messages::VoiceSummary::MSG_TYPE,
120
+ cid: cid,
121
+ call_id: call_id)
122
+ end
123
+
124
+ # Subscribes to chat.voice.summary messages.
125
+ def on_summary(&block)
126
+ @messaging.subscribe :voice_summary do |msg|
127
+ block.call(msg.payload[:iss],
128
+ cid: msg.payload[:cid],
129
+ call_id: msg.payload[:call_id],
130
+ peer_info: msg.payload[:peer_info])
131
+ end
132
+ end
133
+
134
+ private
135
+
136
+ # sends a message to a list of recipients.
137
+ def send(recipients, body)
138
+ recipients = [recipients] if recipients.is_a? String
139
+ m = []
140
+ recipients.each do |r|
141
+ m << @messaging.send(r, body)
142
+ end
143
+ m
144
+ end
145
+ end
146
+ end
147
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: selfsdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.203
4
+ version: 0.0.204
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aldgate Ventures
@@ -392,6 +392,7 @@ files:
392
392
  - lib/services/identity.rb
393
393
  - lib/services/messaging.rb
394
394
  - lib/services/requester.rb
395
+ - lib/services/voice.rb
395
396
  - lib/signature_graph.rb
396
397
  - lib/source_definition.rb
397
398
  - lib/sources.rb