forked from danog/MadelineProto
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVoIP.php
206 lines (182 loc) · 5.6 KB
/
VoIP.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?php declare(strict_types=1);
/**
* This file is part of MadelineProto.
* MadelineProto is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* MadelineProto is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
* You should have received a copy of the GNU General Public License along with MadelineProto.
* If not, see <http://www.gnu.org/licenses/>.
*
* @author Daniil Gentili <[email protected]>
* @copyright 2016-2023 Daniil Gentili <[email protected]>
* @license https://opensource.org/licenses/AGPL-3.0 AGPLv3
* @link https://docs.madelineproto.xyz MadelineProto documentation
*/
namespace danog\MadelineProto;
use Amp\ByteStream\ReadableStream;
use Amp\ByteStream\WritableStream;
use danog\MadelineProto\EventHandler\SimpleFilters;
use danog\MadelineProto\EventHandler\Update;
use danog\MadelineProto\VoIP\CallState;
use danog\MadelineProto\VoIP\DiscardReason;
/**
* This update represents a VoIP Telegram call.
*/
final class VoIP extends Update implements SimpleFilters
{
/** Phone call ID */
public readonly int $callID;
/** Whether the call is an outgoing call */
public readonly bool $outgoing;
/** ID of the other user in the call */
public readonly int $otherID;
/** When was the call created */
public readonly int $date;
/**
* Constructor.
*
* @internal
*/
public function __construct(
MTProto $API,
array $call
) {
parent::__construct($API);
$call['_'] = 'inputPhoneCall';
$this->date = $call['date'];
$this->callID = $call['id'];
if ($call['admin_id'] === $API->getSelf()['id']) {
$this->outgoing = true;
$this->otherID = $call['participant_id'];
} else {
$this->outgoing = false;
$this->otherID = $call['admin_id'];
}
}
/**
* Accept call.
*/
public function accept(): self
{
$this->getClient()->acceptCall($this->callID);
return $this;
}
/**
* Discard call.
*
* @param int<1, 5> $rating Call rating in stars
* @param string $comment Additional comment on call quality.
*/
public function discard(DiscardReason $reason = DiscardReason::HANGUP, ?int $rating = null, ?string $comment = null): self
{
$this->getClient()->discardCall($this->callID, $reason, $rating, $comment);
return $this;
}
/**
* Get call emojis (will return null if the call is not inited yet).
*
* @return ?list{string, string, string, string}
*/
public function getVisualization(): ?array
{
return $this->getClient()->getCallVisualization($this->callID);
}
/**
* Play file.
*/
public function play(LocalFile|RemoteUrl|ReadableStream $file): self
{
$this->getClient()->callPlay($this->callID, $file);
return $this;
}
/**
* Set output file or stream for incoming OPUS audio packets.
*
* Will write an OGG OPUS stream to the specified file or stream.
*/
public function setOutput(LocalFile|WritableStream $file): self
{
$this->getClient()->callSetOutput($this->callID, $file);
return $this;
}
/**
* Play file.
*/
public function then(LocalFile|RemoteUrl|ReadableStream $file): self
{
$this->getClient()->callPlay($this->callID, $file);
return $this;
}
/**
* When called, skips to the next file in the playlist.
*/
public function skip(): self
{
$this->getClient()->skipPlay($this->callID);
return $this;
}
/**
* Stops playing all files, clears the main and the hold playlist.
*/
public function stop(): self
{
$this->getClient()->stopPlay($this->callID);
return $this;
}
/**
* Pauses the currently playing file.
*/
public function pause(): self
{
$this->getClient()->pausePlay($this->callID);
return $this;
}
/**
* Whether the currently playing file is paused.
*
* @return boolean
*/
public function isPaused(): bool
{
return $this->getClient()->isPlayPaused($this->callID);
}
/**
* Resumes the currently playing file.
*/
public function resume(): self
{
$this->getClient()->resumePlay($this->callID);
return $this;
}
/**
* Files to play on hold.
*/
public function playOnHold(LocalFile|RemoteUrl|ReadableStream ...$files): self
{
$this->getClient()->callPlayOnHold($this->callID, ...$files);
return $this;
}
/**
* Get the file that is currently being played.
*
* Will return a string with the object ID of the stream if we're currently playing a stream, otherwise returns the related LocalFile or RemoteUrl.
*/
public function getCurrent(): RemoteUrl|LocalFile|string|null
{
return $this->getClient()->callGetCurrent($this->callID);
}
/**
* Get call state.
*/
public function getCallState(): CallState
{
return $this->getClient()->getCallState($this->callID) ?? CallState::ENDED;
}
/**
* Get call representation.
*/
public function __toString(): string
{
return "call {$this->callID} with {$this->otherID}";
}
}