-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatchStateAbly.cs
56 lines (50 loc) · 1.89 KB
/
MatchStateAbly.cs
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
using System;
using System.Threading.Tasks;
using IO.Ably;
using IO.Ably.Realtime;
namespace GeniusSports.AblyMatchStateSubscriberExample
{
class MatchStateAbly
{
private readonly string sourceId;
private readonly int sportId;
private readonly int fixtureId;
private readonly MatchStatePlatform matchStatePlatform;
public MatchStateAbly(string sourceId, int sportId, int fixtureId, MatchStatePlatform matchStatePlatform)
{
this.sourceId = sourceId;
this.sportId = sportId;
this.fixtureId = fixtureId;
this.matchStatePlatform = matchStatePlatform;
}
private async Task<object> AuthCallback(TokenParams arg)
{
(_, string accessToken) = await matchStatePlatform.GetLiveAccess(sourceId, sportId, fixtureId);
return new TokenDetails
{
Token = accessToken
};
}
public async Task Subscribe(Action<Message> messageReceived)
{
(string channelName, string accessToken) =
await matchStatePlatform.GetLiveAccess(sourceId, sportId, fixtureId);
var ably = new AblyRealtime(new ClientOptions
{
Token = accessToken,
AuthCallback = AuthCallback,
Environment = "geniussports",
FallbackHosts = new[]
{
"geniussports-a-fallback.ably-realtime.com",
"geniussports-b-fallback.ably-realtime.com",
"geniussports-c-fallback.ably-realtime.com",
"geniussports-d-fallback.ably-realtime.com",
"geniussports-e-fallback.ably-realtime.com"
}
});
IRealtimeChannel channel = ably.Channels.Get(channelName);
channel.Subscribe(messageReceived);
}
}
}