|
1 | | -// <auto-generated> |
| 1 | +namespace StreamVideo.Core.Sfu { |
| 2 | +using Signal = StreamVideo.v1.Sfu.Signal; |
2 | 3 | // Generated by protoc-gen-twirpcs. DO NOT EDIT! |
3 | 4 | // </auto-generated> |
4 | 5 | using System.Net.Http; |
5 | 6 | using System.Net.Http.Headers; |
6 | 7 | using System.Threading.Tasks; |
7 | 8 | using Google.Protobuf; // For ".ToByteArray()" |
8 | | -using Signal = StreamVideo.v1.Sfu.Signal; |
9 | | - |
10 | | -namespace StreamVideo.Core.Sfu |
11 | | -{ |
12 | | - |
13 | | - internal class GeneratedAPI |
14 | | - { |
15 | | - public static readonly MediaTypeWithQualityHeaderValue CONTENT_TYPE_PROTOBUF = new MediaTypeWithQualityHeaderValue("application/protobuf"); |
16 | | - |
17 | | - public enum ErrorCode |
18 | | - { |
19 | | - NoError, Canceled, Unknown, Invalid_Argument, Malformed, Deadline_Exceeded, Not_Found, Bad_Route, Already_Exists, Permission_Denied, |
20 | | - Unauthenticated, Resource_Exhausted, Failed_Precondition, Aborted, Out_Of_Range, Unimplemented, Internal, Unavailable, Data_Loss |
21 | | - }; |
22 | | - |
23 | | - public class Exception : System.Exception |
24 | | - { |
25 | | - public readonly ErrorCode Type; |
26 | | - |
27 | | - public Exception(ErrorCode type, string message) : base(message) { Type = type; } |
28 | | - } |
29 | | - |
30 | | - private static GeneratedAPI.Exception createException(string jsonData) |
31 | | - { |
32 | | - var codeStr = parseJSONString(jsonData, "code"); |
33 | | - if (codeStr == null) |
34 | | - { |
35 | | - return new GeneratedAPI.Exception(ErrorCode.Unknown, jsonData); |
36 | | - } |
37 | | - |
38 | | - ErrorCode errorCode = ErrorCode.Unknown; |
39 | | - System.Enum.TryParse<ErrorCode>(codeStr, true, out errorCode); |
40 | | - var msg = parseJSONString(jsonData, "msg"); |
41 | | - if (msg == null) |
42 | | - { |
43 | | - msg = jsonData; |
44 | | - } |
45 | | - return new GeneratedAPI.Exception(errorCode, msg); |
46 | | - } |
47 | | - |
48 | | - private static string parseJSONString(string jsonData, string key) |
49 | | - { |
50 | | - var keyIndex = jsonData.IndexOf(key + "\":\""); |
51 | | - if (keyIndex == -1) { return null; } |
52 | | - keyIndex += key.Length + 3; |
53 | | - var dataEnd = jsonData.IndexOf("\"", keyIndex); |
54 | | - if (dataEnd == -1) { return null; } |
55 | | - return jsonData.Substring(keyIndex, dataEnd - keyIndex); |
56 | | - } |
57 | 9 |
|
58 | | - private delegate Resp doParsing<Resp>(byte[] data) where Resp : IMessage; |
59 | | - private static async Task<Resp> DoRequest<Req, Resp>(HttpClient client, string address, Req req, doParsing<Resp> parserFunc) where Req : IMessage where Resp : IMessage |
60 | | - { |
61 | | - using (var content = new ByteArrayContent(req.ToByteArray())) |
62 | | - { |
63 | | - content.Headers.ContentType = CONTENT_TYPE_PROTOBUF; |
64 | | - using (HttpResponseMessage response = await client.PostAsync(address, content)) |
65 | | - { |
66 | | - var byteArr = await response.Content.ReadAsByteArrayAsync(); |
67 | | - if (!response.IsSuccessStatusCode) |
68 | | - { |
69 | | - string errorJSON = System.Text.Encoding.UTF8.GetString(byteArr, 0, byteArr.Length); |
70 | | - throw createException(errorJSON); |
71 | | - } |
72 | | - return parserFunc(byteArr); |
73 | | - } |
74 | | - } |
75 | | - } |
76 | | - |
77 | | - // SetPublisher sends the WebRTC offer for the peer connection used to publish A/V |
78 | | - public static async Task<Signal.SetPublisherResponse> SetPublisher(HttpClient client, Signal.SetPublisherRequest req) |
79 | | - { |
80 | | - return await DoRequest<Signal.SetPublisherRequest, Signal.SetPublisherResponse>(client, "/twirp/stream.video.sfu.signal.SignalServer/SetPublisher", req, Signal.SetPublisherResponse.Parser.ParseFrom); |
81 | | - } |
| 10 | +internal class GeneratedAPI { |
| 11 | + public static readonly MediaTypeWithQualityHeaderValue CONTENT_TYPE_PROTOBUF = new MediaTypeWithQualityHeaderValue("application/protobuf"); |
82 | 12 |
|
83 | | - // answer is sent by the client to the SFU after receiving a subscriber_offer. |
84 | | - public static async Task<Signal.SendAnswerResponse> SendAnswer(HttpClient client, Signal.SendAnswerRequest req) |
85 | | - { |
86 | | - return await DoRequest<Signal.SendAnswerRequest, Signal.SendAnswerResponse>(client, "/twirp/stream.video.sfu.signal.SignalServer/SendAnswer", req, Signal.SendAnswerResponse.Parser.ParseFrom); |
87 | | - } |
88 | | - |
89 | | - // SendICECandidate sends an ICE candidate to the client |
90 | | - public static async Task<Signal.ICETrickleResponse> IceTrickle(HttpClient client, StreamVideo.v1.Sfu.Models.ICETrickle req) |
91 | | - { |
92 | | - return await DoRequest<StreamVideo.v1.Sfu.Models.ICETrickle, Signal.ICETrickleResponse>(client, "/twirp/stream.video.sfu.signal.SignalServer/IceTrickle", req, Signal.ICETrickleResponse.Parser.ParseFrom); |
93 | | - } |
| 13 | + public enum ErrorCode { |
| 14 | + NoError, Canceled, Unknown, Invalid_Argument, Malformed, Deadline_Exceeded, Not_Found, Bad_Route, Already_Exists, Permission_Denied, |
| 15 | + Unauthenticated, Resource_Exhausted, Failed_Precondition, Aborted, Out_Of_Range, Unimplemented, Internal, Unavailable, Data_Loss |
| 16 | + }; |
94 | 17 |
|
95 | | - // UpdateSubscribers is used to notify the SFU about the list of video subscriptions |
96 | | - // TODO: sync subscriptions based on this + update tracks using the dimension info sent by the user |
97 | | - public static async Task<Signal.UpdateSubscriptionsResponse> UpdateSubscriptions(HttpClient client, Signal.UpdateSubscriptionsRequest req) |
98 | | - { |
99 | | - return await DoRequest<Signal.UpdateSubscriptionsRequest, Signal.UpdateSubscriptionsResponse>(client, "/twirp/stream.video.sfu.signal.SignalServer/UpdateSubscriptions", req, Signal.UpdateSubscriptionsResponse.Parser.ParseFrom); |
100 | | - } |
| 18 | + public class Exception : System.Exception { |
| 19 | + public readonly ErrorCode Type; |
101 | 20 |
|
102 | | - public static async Task<Signal.UpdateMuteStatesResponse> UpdateMuteStates(HttpClient client, Signal.UpdateMuteStatesRequest req) |
103 | | - { |
104 | | - return await DoRequest<Signal.UpdateMuteStatesRequest, Signal.UpdateMuteStatesResponse>(client, "/twirp/stream.video.sfu.signal.SignalServer/UpdateMuteStates", req, Signal.UpdateMuteStatesResponse.Parser.ParseFrom); |
105 | | - } |
| 21 | + public Exception(ErrorCode type, string message) : base(message) { Type = type; } |
| 22 | + } |
106 | 23 |
|
107 | | - public static async Task<Signal.ICERestartResponse> IceRestart(HttpClient client, Signal.ICERestartRequest req) |
108 | | - { |
109 | | - return await DoRequest<Signal.ICERestartRequest, Signal.ICERestartResponse>(client, "/twirp/stream.video.sfu.signal.SignalServer/IceRestart", req, Signal.ICERestartResponse.Parser.ParseFrom); |
110 | | - } |
| 24 | + private static GeneratedAPI.Exception createException(string jsonData) { |
| 25 | + var codeStr = parseJSONString(jsonData, "code"); |
| 26 | + if (codeStr == null) { |
| 27 | + return new GeneratedAPI.Exception(ErrorCode.Unknown, jsonData); |
| 28 | + } |
111 | 29 |
|
112 | | - public static async Task<Signal.SendStatsResponse> SendStats(HttpClient client, Signal.SendStatsRequest req) |
113 | | - { |
114 | | - return await DoRequest<Signal.SendStatsRequest, Signal.SendStatsResponse>(client, "/twirp/stream.video.sfu.signal.SignalServer/SendStats", req, Signal.SendStatsResponse.Parser.ParseFrom); |
| 30 | + ErrorCode errorCode = ErrorCode.Unknown; |
| 31 | + System.Enum.TryParse<ErrorCode>(codeStr, true, out errorCode); |
| 32 | + var msg = parseJSONString(jsonData, "msg"); |
| 33 | + if (msg == null) { |
| 34 | + msg = jsonData; |
| 35 | + } |
| 36 | + return new GeneratedAPI.Exception(errorCode, msg); |
| 37 | + } |
| 38 | + |
| 39 | + private static string parseJSONString(string jsonData, string key) { |
| 40 | + var keyIndex = jsonData.IndexOf(key + "\":\""); |
| 41 | + if (keyIndex == -1) { return null; } |
| 42 | + keyIndex += key.Length + 3; |
| 43 | + var dataEnd = jsonData.IndexOf("\"", keyIndex); |
| 44 | + if (dataEnd == -1) { return null; } |
| 45 | + return jsonData.Substring(keyIndex, dataEnd - keyIndex); |
| 46 | + } |
| 47 | + |
| 48 | + private delegate Resp doParsing<Resp>(byte[] data) where Resp : IMessage; |
| 49 | + private static async Task<Resp> DoRequest<Req, Resp>(HttpClient client, string address, Req req, doParsing<Resp> parserFunc) where Req : IMessage where Resp : IMessage { |
| 50 | + using (var content = new ByteArrayContent(req.ToByteArray())) { |
| 51 | + content.Headers.ContentType = CONTENT_TYPE_PROTOBUF; |
| 52 | + using (HttpResponseMessage response = await client.PostAsync(address, content)) { |
| 53 | + var byteArr = await response.Content.ReadAsByteArrayAsync(); |
| 54 | + if (!response.IsSuccessStatusCode) { |
| 55 | + string errorJSON = System.Text.Encoding.UTF8.GetString(byteArr, 0, byteArr.Length); |
| 56 | + throw createException(errorJSON); |
115 | 57 | } |
| 58 | + return parserFunc(byteArr); |
| 59 | + } |
116 | 60 | } |
| 61 | + } |
| 62 | + |
| 63 | + // SetPublisher sends the WebRTC offer for the peer connection used to publish A/V |
| 64 | + public static async Task<Signal.SetPublisherResponse> SetPublisher(HttpClient client, Signal.SetPublisherRequest req) { |
| 65 | + return await DoRequest<Signal.SetPublisherRequest, Signal.SetPublisherResponse>(client, "/twirp/stream.video.sfu.signal.SignalServer/SetPublisher", req, Signal.SetPublisherResponse.Parser.ParseFrom); |
| 66 | + } |
| 67 | + |
| 68 | + // answer is sent by the client to the SFU after receiving a subscriber_offer. |
| 69 | + public static async Task<Signal.SendAnswerResponse> SendAnswer(HttpClient client, Signal.SendAnswerRequest req) { |
| 70 | + return await DoRequest<Signal.SendAnswerRequest, Signal.SendAnswerResponse>(client, "/twirp/stream.video.sfu.signal.SignalServer/SendAnswer", req, Signal.SendAnswerResponse.Parser.ParseFrom); |
| 71 | + } |
| 72 | + |
| 73 | + // SendICECandidate sends an ICE candidate to the client |
| 74 | + public static async Task<StreamVideo.v1.Sfu.Signal.ICETrickleResponse> IceTrickle(HttpClient client, StreamVideo.v1.Sfu.Models.ICETrickle req) { |
| 75 | + return await DoRequest<StreamVideo.v1.Sfu.Models.ICETrickle, StreamVideo.v1.Sfu.Signal.ICETrickleResponse>(client, "/twirp/stream.video.sfu.signal.SignalServer/IceTrickle", req, StreamVideo.v1.Sfu.Signal.ICETrickleResponse.Parser.ParseFrom); |
| 76 | + } |
| 77 | + |
| 78 | + // UpdateSubscribers is used to notify the SFU about the list of video subscriptions |
| 79 | + // TODO: sync subscriptions based on this + update tracks using the dimension info sent by the user |
| 80 | + public static async Task<Signal.UpdateSubscriptionsResponse> UpdateSubscriptions(HttpClient client, Signal.UpdateSubscriptionsRequest req) { |
| 81 | + return await DoRequest<Signal.UpdateSubscriptionsRequest, Signal.UpdateSubscriptionsResponse>(client, "/twirp/stream.video.sfu.signal.SignalServer/UpdateSubscriptions", req, Signal.UpdateSubscriptionsResponse.Parser.ParseFrom); |
| 82 | + } |
| 83 | + |
| 84 | + public static async Task<Signal.UpdateMuteStatesResponse> UpdateMuteStates(HttpClient client, Signal.UpdateMuteStatesRequest req) { |
| 85 | + return await DoRequest<Signal.UpdateMuteStatesRequest, Signal.UpdateMuteStatesResponse>(client, "/twirp/stream.video.sfu.signal.SignalServer/UpdateMuteStates", req, Signal.UpdateMuteStatesResponse.Parser.ParseFrom); |
| 86 | + } |
| 87 | + |
| 88 | + public static async Task<Signal.ICERestartResponse> IceRestart(HttpClient client, Signal.ICERestartRequest req) { |
| 89 | + return await DoRequest<Signal.ICERestartRequest, Signal.ICERestartResponse>(client, "/twirp/stream.video.sfu.signal.SignalServer/IceRestart", req, Signal.ICERestartResponse.Parser.ParseFrom); |
| 90 | + } |
| 91 | + |
| 92 | + public static async Task<Signal.SendStatsResponse> SendStats(HttpClient client, Signal.SendStatsRequest req) { |
| 93 | + return await DoRequest<Signal.SendStatsRequest, Signal.SendStatsResponse>(client, "/twirp/stream.video.sfu.signal.SignalServer/SendStats", req, Signal.SendStatsResponse.Parser.ParseFrom); |
| 94 | + } |
| 95 | + |
| 96 | + public static async Task<Signal.StartNoiseCancellationResponse> StartNoiseCancellation(HttpClient client, Signal.StartNoiseCancellationRequest req) { |
| 97 | + return await DoRequest<Signal.StartNoiseCancellationRequest, Signal.StartNoiseCancellationResponse>(client, "/twirp/stream.video.sfu.signal.SignalServer/StartNoiseCancellation", req, Signal.StartNoiseCancellationResponse.Parser.ParseFrom); |
| 98 | + } |
| 99 | + |
| 100 | + public static async Task<Signal.StopNoiseCancellationResponse> StopNoiseCancellation(HttpClient client, Signal.StopNoiseCancellationRequest req) { |
| 101 | + return await DoRequest<Signal.StopNoiseCancellationRequest, Signal.StopNoiseCancellationResponse>(client, "/twirp/stream.video.sfu.signal.SignalServer/StopNoiseCancellation", req, Signal.StopNoiseCancellationResponse.Parser.ParseFrom); |
| 102 | + } |
| 103 | +} |
117 | 104 | } |
0 commit comments