forked from jsanahuja/php-peer-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCall.php
More file actions
71 lines (56 loc) · 1.75 KB
/
Copy pathCall.php
File metadata and controls
71 lines (56 loc) · 1.75 KB
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
<?php
namespace Sowe\PHPPeerServer;
use Sowe\PHPPeerServer\Client;
use Sowe\PHPPeerServer\Room;
class Call{
private $id;
private $client1;
private $client2;
private $offer;
private $answer;
public function __construct(Room $room, Client $client1, Client $client2){
$this->id = $room->getId() . $client1->getId() . $client2->getId();
$this->client1 = $client1;
$this->client2 = $client2;
$this->init();
}
/**
* Call workflow
*/
public function init(){
$this->client1->getSocket()->emit("call", $this->id);
}
public function offer($offer){
$this->client2->getSocket()->emit("offer", $this->id, $offer);
}
public function answer($answer){
$this->client1->getSocket()->emit("answer", $this->id, $answer);
}
public function hangup(){
$this->client1->getSocket()->emit("hangup", $this->id);
$this->client2->getSocket()->emit("hangup", $this->id);
}
public function candidate($client, $candidate){
if($this->client1->equals($client)){
$this->client2->getSocket()->emit("candidate", $this->id, $candidate);
}else if($this->client2->equals($client)){
$this->client1->getSocket()->emit("candidate", $this->id, $candidate);
}
}
/**
* Helpers
*/
public function getId(){
return $this->id;
}
public function clientCanOffer(Client $client){
return $this->client1->equals($client);
}
public function clientCanAnswer(Client $client){
return $this->client2->equals($client);
}
public function contains(Client $client){
return $this->client1->equals($client) ||
$this->client2->equals($client);
}
}