|
1
|
|
|
<?php |
|
2
|
|
|
/******************************************************************************* |
|
3
|
|
|
* This file is part of the GraphQL Bundle package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) YnloUltratech <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
******************************************************************************/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Ynlo\GraphQLBundle\Subscription; |
|
12
|
|
|
|
|
13
|
|
|
use Ynlo\GraphQLBundle\Annotation as GraphQL; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @GraphQL\ObjectType(description=" |
|
17
|
|
|
The subscription link have all required information to subscribe to server events. |
|
18
|
|
|
|
|
19
|
|
|
Can susbribe to a service using something like: |
|
20
|
|
|
|
|
21
|
|
|
new EventSource(subscription.url) |
|
22
|
|
|
|
|
23
|
|
|
**NOTE:** A subscription have a tll (Time to live), you must call a periodic request (heartbeat) to |
|
24
|
|
|
the `heartbeatUrl` in order to keep-alive the subscription. Otherwise the subscription will be not available |
|
25
|
|
|
after the specified ttl. |
|
26
|
|
|
") |
|
27
|
|
|
*/ |
|
28
|
|
|
class SubscriptionLink |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* @var string |
|
32
|
|
|
* |
|
33
|
|
|
* @GraphQL\Field(type="string!", description="corresponding subscription url containing a unique subscription ID. The client can |
|
34
|
|
|
subscribe to the event stream corresponding to this subscription by creating a `new EventSource`.") |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $url; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @var string |
|
40
|
|
|
* |
|
41
|
|
|
* @GraphQL\Field(type="string!", description="Url to send periodicals requests (heartbeats) to keep-alive the subscription.") |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $heartbeatUrl; |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @var int |
|
47
|
|
|
* |
|
48
|
|
|
* @GraphQL\Field(type="int!", description="Time to live(in seconds) for a subscription, must call a heartbeat to keep the subscription alive") |
|
49
|
|
|
*/ |
|
50
|
|
|
protected $ttl; |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* SubscriptionLink constructor. |
|
54
|
|
|
* |
|
55
|
|
|
* @param string $url |
|
56
|
|
|
* @param string $heartbeatUrl |
|
57
|
|
|
* @param integer $ttl |
|
58
|
|
|
*/ |
|
59
|
|
|
public function __construct(string $url, $heartbeatUrl, int $ttl) |
|
60
|
|
|
{ |
|
61
|
|
|
$this->url = $url; |
|
62
|
|
|
$this->heartbeatUrl = $heartbeatUrl; |
|
63
|
|
|
$this->ttl = $ttl; |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return string |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getUrl(): string |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->url; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @return string |
|
76
|
|
|
*/ |
|
77
|
|
|
public function getHeartbeatUrl(): string |
|
78
|
|
|
{ |
|
79
|
|
|
return $this->heartbeatUrl; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return int |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getTtl(): int |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->ttl; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|