webrtc-ruby 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +7 -0
  2. data/.dockerignore +19 -0
  3. data/.rspec +3 -0
  4. data/CHANGELOG.md +12 -0
  5. data/Dockerfile +49 -0
  6. data/LICENSE +201 -0
  7. data/README.md +264 -0
  8. data/Rakefile +42 -0
  9. data/examples/signaling_server/server.rb +200 -0
  10. data/examples/simple_data_channel.rb +81 -0
  11. data/examples/video_call.rb +152 -0
  12. data/ext/webrtc_ruby/CMakeLists.txt +84 -0
  13. data/ext/webrtc_ruby/Makefile +31 -0
  14. data/ext/webrtc_ruby/webrtc_ruby.c +994 -0
  15. data/ext/webrtc_ruby/webrtc_ruby.h +212 -0
  16. data/lib/webrtc/configuration.rb +99 -0
  17. data/lib/webrtc/data_channel.rb +216 -0
  18. data/lib/webrtc/dtls_transport.rb +54 -0
  19. data/lib/webrtc/dtmf_sender.rb +81 -0
  20. data/lib/webrtc/errors.rb +10 -0
  21. data/lib/webrtc/factory.rb +28 -0
  22. data/lib/webrtc/ffi/library.rb +122 -0
  23. data/lib/webrtc/ice_candidate.rb +63 -0
  24. data/lib/webrtc/ice_transport.rb +95 -0
  25. data/lib/webrtc/media_interfaces.rb +101 -0
  26. data/lib/webrtc/media_stream.rb +67 -0
  27. data/lib/webrtc/media_stream_track.rb +83 -0
  28. data/lib/webrtc/observers.rb +51 -0
  29. data/lib/webrtc/parity_types.rb +358 -0
  30. data/lib/webrtc/peer_connection.rb +577 -0
  31. data/lib/webrtc/promise.rb +59 -0
  32. data/lib/webrtc/rtp_receiver.rb +79 -0
  33. data/lib/webrtc/rtp_sender.rb +117 -0
  34. data/lib/webrtc/rtp_transceiver.rb +39 -0
  35. data/lib/webrtc/sctp_transport.rb +31 -0
  36. data/lib/webrtc/session_description.rb +65 -0
  37. data/lib/webrtc/stats_report.rb +199 -0
  38. data/lib/webrtc/version.rb +5 -0
  39. data/lib/webrtc/video_frame.rb +29 -0
  40. data/lib/webrtc.rb +43 -0
  41. data/webrtc-ruby.gemspec +33 -0
  42. metadata +113 -0
@@ -0,0 +1,358 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WebRTC
4
+ module RTCIceTransportPolicy
5
+ ALL = :all
6
+ RELAY = :relay
7
+ VALUES = [ALL, RELAY].freeze
8
+ end
9
+
10
+ module RTCBundlePolicy
11
+ BALANCED = :balanced
12
+ MAX_COMPAT = :max_compat
13
+ MAX_BUNDLE = :max_bundle
14
+ VALUES = [BALANCED, MAX_COMPAT, MAX_BUNDLE].freeze
15
+ end
16
+
17
+ module RTCRtcpMuxPolicy
18
+ REQUIRE = :require
19
+ VALUES = [REQUIRE].freeze
20
+ end
21
+
22
+ module RTCPeerConnectionState
23
+ VALUES = %i[new connecting connected disconnected failed closed].freeze
24
+ end
25
+
26
+ module RTCSignalingState
27
+ VALUES = %i[stable have_local_offer have_remote_offer have_local_pranswer have_remote_pranswer closed].freeze
28
+ end
29
+
30
+ module RTCIceConnectionState
31
+ VALUES = %i[new checking connected completed failed disconnected closed].freeze
32
+ end
33
+
34
+ module RTCIceGatheringState
35
+ VALUES = %i[new gathering complete].freeze
36
+ end
37
+
38
+ module DataChannelState
39
+ VALUES = %i[connecting open closing closed].freeze
40
+ end
41
+
42
+ module RTPCodecType
43
+ AUDIO = :audio
44
+ VIDEO = :video
45
+ VALUES = [AUDIO, VIDEO].freeze
46
+ end
47
+
48
+ module RTCSdpType
49
+ OFFER = :offer
50
+ ANSWER = :answer
51
+ PRANSWER = :pranswer
52
+ ROLLBACK = :rollback
53
+ VALUES = [OFFER, ANSWER, PRANSWER, ROLLBACK].freeze
54
+ end
55
+
56
+ module MediaType
57
+ AUDIO = :audio
58
+ VIDEO = :video
59
+ DATA = :data
60
+ VALUES = [AUDIO, VIDEO, DATA].freeze
61
+ end
62
+
63
+ module RTCErrorType
64
+ NONE = :none
65
+ UNSUPPORTED_OPERATION = :unsupported_operation
66
+ INVALID_PARAMETER = :invalid_parameter
67
+ INVALID_STATE = :invalid_state
68
+ NETWORK = :network
69
+ INTERNAL = :internal
70
+ VALUES = [NONE, UNSUPPORTED_OPERATION, INVALID_PARAMETER, INVALID_STATE, NETWORK, INTERNAL].freeze
71
+ end
72
+
73
+ module RTCErrorDetailType
74
+ NONE = :none
75
+ DATA_CHANNEL_FAILURE = :data_channel_failure
76
+ SDP_SYNTAX_ERROR = :sdp_syntax_error
77
+ IDENTITY_FAILURE = :identity_failure
78
+ DTLS_FAILURE = :dtls_failure
79
+ SCTP_FAILURE = :sctp_failure
80
+ VALUES = [NONE, DATA_CHANNEL_FAILURE, SDP_SYNTAX_ERROR, IDENTITY_FAILURE, DTLS_FAILURE, SCTP_FAILURE].freeze
81
+ end
82
+
83
+ class RTCError < StandardError
84
+ attr_reader :error_type, :error_detail, :sdp_line_number, :status_code
85
+
86
+ def initialize(message:, error_type: RTCErrorType::INTERNAL, error_detail: RTCErrorDetailType::NONE,
87
+ sdp_line_number: nil, status_code: nil)
88
+ super(message)
89
+ @error_type = error_type
90
+ @error_detail = error_detail
91
+ @sdp_line_number = sdp_line_number
92
+ @status_code = status_code
93
+ end
94
+
95
+ def to_h
96
+ {
97
+ message: message,
98
+ errorType: @error_type,
99
+ errorDetail: @error_detail,
100
+ sdpLineNumber: @sdp_line_number,
101
+ statusCode: @status_code
102
+ }
103
+ end
104
+ end
105
+
106
+ class RTCCertificate
107
+ attr_reader :expires, :fingerprints
108
+
109
+ def initialize(expires:, fingerprints: [])
110
+ @expires = expires
111
+ @fingerprints = fingerprints
112
+ end
113
+ end
114
+
115
+ class RTCEncodedImage
116
+ attr_reader :data, :timestamp, :frame_type, :width, :height
117
+
118
+ def initialize(data:, timestamp:, frame_type:, width:, height:)
119
+ @data = data
120
+ @timestamp = timestamp
121
+ @frame_type = frame_type
122
+ @width = width
123
+ @height = height
124
+ end
125
+ end
126
+
127
+ class CreateOfferOptions
128
+ attr_accessor :ice_restart, :voice_activity_detection
129
+
130
+ def initialize(ice_restart: false, voice_activity_detection: true)
131
+ @ice_restart = ice_restart
132
+ @voice_activity_detection = voice_activity_detection
133
+ end
134
+
135
+ def to_h
136
+ {
137
+ ice_restart: @ice_restart,
138
+ voice_activity_detection: @voice_activity_detection
139
+ }
140
+ end
141
+ end
142
+
143
+ class CreateAnswerOptions
144
+ attr_accessor :voice_activity_detection
145
+
146
+ def initialize(voice_activity_detection: true)
147
+ @voice_activity_detection = voice_activity_detection
148
+ end
149
+
150
+ def to_h
151
+ { voice_activity_detection: @voice_activity_detection }
152
+ end
153
+ end
154
+
155
+ class RTCSessionDescriptionInit
156
+ attr_reader :type, :sdp
157
+
158
+ def initialize(type:, sdp:)
159
+ @type = type
160
+ @sdp = sdp
161
+ end
162
+
163
+ def to_h
164
+ { type: @type, sdp: @sdp }
165
+ end
166
+ end
167
+
168
+ class RTCIceCandidateInit
169
+ attr_reader :candidate, :sdp_mid, :sdp_m_line_index, :username_fragment
170
+
171
+ def initialize(candidate:, sdp_mid: nil, sdp_m_line_index: nil, username_fragment: nil)
172
+ @candidate = candidate
173
+ @sdp_mid = sdp_mid
174
+ @sdp_m_line_index = sdp_m_line_index
175
+ @username_fragment = username_fragment
176
+ end
177
+
178
+ def to_h
179
+ {
180
+ candidate: @candidate,
181
+ sdp_mid: @sdp_mid,
182
+ sdp_m_line_index: @sdp_m_line_index,
183
+ username_fragment: @username_fragment
184
+ }
185
+ end
186
+ end
187
+
188
+ class DataChannelInit
189
+ attr_reader :ordered, :max_packet_life_time, :max_retransmits, :protocol, :negotiated, :id
190
+
191
+ def initialize(ordered: true, max_packet_life_time: nil, max_retransmits: nil, protocol: '', negotiated: false,
192
+ id: nil)
193
+ @ordered = ordered
194
+ @max_packet_life_time = max_packet_life_time
195
+ @max_retransmits = max_retransmits
196
+ @protocol = protocol
197
+ @negotiated = negotiated
198
+ @id = id
199
+ end
200
+
201
+ def to_h
202
+ {
203
+ ordered: @ordered,
204
+ max_packet_life_time: @max_packet_life_time,
205
+ max_retransmits: @max_retransmits,
206
+ protocol: @protocol,
207
+ negotiated: @negotiated,
208
+ id: @id
209
+ }
210
+ end
211
+ end
212
+
213
+ class DataChannelMessage
214
+ attr_reader :data
215
+
216
+ def initialize(data, is_binary)
217
+ @data = data
218
+ @is_binary = is_binary
219
+ end
220
+
221
+ def binary?
222
+ @is_binary
223
+ end
224
+
225
+ def text?
226
+ !@is_binary
227
+ end
228
+ end
229
+
230
+ class RTCTrackEvent
231
+ attr_reader :track, :receiver, :transceiver, :streams
232
+
233
+ def initialize(track:, receiver:, transceiver:, streams:)
234
+ @track = track
235
+ @receiver = receiver
236
+ @transceiver = transceiver
237
+ @streams = streams
238
+ end
239
+ end
240
+
241
+ class RTCRtpHeaderExtensionCapability
242
+ attr_reader :uri
243
+
244
+ def initialize(uri:)
245
+ @uri = uri
246
+ end
247
+ end
248
+
249
+ class RTCRtcpFeedback
250
+ attr_reader :type, :parameter
251
+
252
+ def initialize(type:, parameter: nil)
253
+ @type = type
254
+ @parameter = parameter
255
+ end
256
+ end
257
+
258
+ class RTCRtpCodecCapability
259
+ attr_reader :mime_type, :clock_rate, :channels, :sdp_fmtp_line, :rtcp_feedback
260
+
261
+ def initialize(mime_type:, clock_rate:, channels: nil, sdp_fmtp_line: nil, rtcp_feedback: [])
262
+ @mime_type = mime_type
263
+ @clock_rate = clock_rate
264
+ @channels = channels
265
+ @sdp_fmtp_line = sdp_fmtp_line
266
+ @rtcp_feedback = rtcp_feedback
267
+ end
268
+ end
269
+
270
+ class RTCRtpCapabilities
271
+ attr_reader :codecs, :header_extensions
272
+
273
+ def initialize(codecs:, header_extensions: [])
274
+ @codecs = codecs
275
+ @header_extensions = header_extensions
276
+ end
277
+ end
278
+
279
+ class RTCRtpCodecParameters
280
+ attr_accessor :payload_type, :mime_type, :clock_rate, :channels, :sdp_fmtp_line
281
+
282
+ def initialize(payload_type:, mime_type:, clock_rate:, channels: nil, sdp_fmtp_line: nil)
283
+ @payload_type = payload_type
284
+ @mime_type = mime_type
285
+ @clock_rate = clock_rate
286
+ @channels = channels
287
+ @sdp_fmtp_line = sdp_fmtp_line
288
+ end
289
+ end
290
+
291
+ class RTCRtpEncodingParameters
292
+ attr_accessor :ssrc, :rid, :active, :max_bitrate, :scale_resolution_down_by
293
+
294
+ def initialize(ssrc: nil, rid: nil, active: true, max_bitrate: nil, scale_resolution_down_by: nil)
295
+ @ssrc = ssrc
296
+ @rid = rid
297
+ @active = active
298
+ @max_bitrate = max_bitrate
299
+ @scale_resolution_down_by = scale_resolution_down_by
300
+ end
301
+ end
302
+
303
+ class RTCRtpHeaderExtensionParameters
304
+ attr_accessor :uri, :id, :encrypted
305
+
306
+ def initialize(uri:, id:, encrypted: false)
307
+ @uri = uri
308
+ @id = id
309
+ @encrypted = encrypted
310
+ end
311
+ end
312
+
313
+ class RTCRtcpParameters
314
+ attr_accessor :cname, :reduced_size
315
+
316
+ def initialize(cname: '', reduced_size: false)
317
+ @cname = cname
318
+ @reduced_size = reduced_size
319
+ end
320
+ end
321
+
322
+ class RTCRtpSendParameters
323
+ attr_accessor :transaction_id, :encodings, :header_extensions, :rtcp, :codecs
324
+
325
+ def initialize(transaction_id: '', encodings: [], header_extensions: [], rtcp: RTCRtcpParameters.new, codecs: [])
326
+ @transaction_id = transaction_id
327
+ @encodings = encodings
328
+ @header_extensions = header_extensions
329
+ @rtcp = rtcp
330
+ @codecs = codecs
331
+ end
332
+ end
333
+
334
+ class RTCRtpReceiveParameters
335
+ attr_accessor :header_extensions, :rtcp, :codecs
336
+
337
+ def initialize(header_extensions: [], rtcp: RTCRtcpParameters.new, codecs: [])
338
+ @header_extensions = header_extensions
339
+ @rtcp = rtcp
340
+ @codecs = codecs
341
+ end
342
+ end
343
+
344
+ class RTCStatsResponse
345
+ include Enumerable
346
+
347
+ attr_reader :report
348
+
349
+ def initialize(report)
350
+ @report = report
351
+ end
352
+
353
+ def each(&block)
354
+ @report.each(&block)
355
+ end
356
+ end
357
+
358
+ end