@@ -63,6 +63,9 @@ <h3>Pion</h3>
63
63
</ div >
64
64
</ div >
65
65
66
+ < div class ="row ">
67
+ < div class ="col-12 pt-4 "> Media</ div >
68
+ </ div >
66
69
< div class ="row ">
67
70
< div class ="col-6 pt-2 ">
68
71
< span
@@ -263,11 +266,50 @@ <h3>Pion</h3>
263
266
< pre
264
267
id ="api "
265
268
class ="d-block border "
266
- style ="background-color: #f8f9fa; height: 117px "
269
+ style ="
270
+ background-color: #f8f9fa;
271
+ height: 117px;
272
+ width: 320px;
273
+ margin: 5px 0;
274
+ "
267
275
> </ pre >
268
276
</ div >
269
277
</ div >
270
278
</ div >
279
+ < div class ="row ">
280
+ < div class ="col-12 pt-4 "> Data</ div >
281
+ </ div >
282
+ < div class ="row ">
283
+ < div class ="col-6 pt-2 ">
284
+ < textarea
285
+ id ="local-data "
286
+ class ="d-block border "
287
+ style ="
288
+ background-color: #f8f9fa;
289
+ height: 117px;
290
+ width: 320px;
291
+ margin: 5px 0;
292
+ padding: 5px;
293
+ "
294
+ placeholder ="Send a message "
295
+ > </ textarea >
296
+ < button type ="button " class ="btn btn-primary " onclick ="send() ">
297
+ send
298
+ </ button >
299
+ </ div >
300
+ < div class ="col-6 pt-2 ">
301
+ < pre
302
+ id ="remote-data "
303
+ class ="d-block border "
304
+ style ="
305
+ background-color: #f8f9fa;
306
+ height: 117px;
307
+ width: 320px;
308
+ margin: 5px 0;
309
+ "
310
+ > </ pre >
311
+ </ div >
312
+ </ div >
271
313
</ div >
272
314
<!-- Optional JavaScript -->
273
315
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
@@ -286,13 +328,16 @@ <h3>Pion</h3>
286
328
integrity ="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV "
287
329
crossorigin ="anonymous "
288
330
> </ script >
289
- < script src ="https://unpkg.com/ion-sdk-js@1.4.1 /dist/ion-sdk.min.js "> </ script >
331
+ < script src ="https://unpkg.com/ion-sdk-js@1.5.0 /dist/ion-sdk.min.js "> </ script >
290
332
< script >
291
333
const localVideo = document . getElementById ( "local-video" ) ;
292
334
const remoteVideo = document . getElementById ( "remote-video" ) ;
335
+ const localData = document . getElementById ( "local-data" ) ;
336
+ const remoteData = document . getElementById ( "remote-data" ) ;
293
337
const sizeTag = document . getElementById ( "size-tag" ) ;
294
338
const brTag = document . getElementById ( "br-tag" ) ;
295
339
let simulcast = false ;
340
+ let localDataChannel ;
296
341
297
342
remoteVideo . addEventListener ( "loadedmetadata" , function ( ) {
298
343
sizeTag . innerHTML = `${ remoteVideo . videoWidth } x${ remoteVideo . videoHeight } ` ;
@@ -325,14 +370,21 @@ <h3>Pion</h3>
325
370
} )
326
371
. then ( ( media ) => {
327
372
localStream = media ;
328
- localVideo . srcObject = media . stream ;
373
+ localVideo . srcObject = media ;
329
374
localVideo . autoplay = true ;
330
375
localVideo . controls = true ;
331
376
localVideo . muted = true ;
332
377
joinBtns . style . display = "none" ;
333
378
clientLocal . publish ( media ) ;
334
379
} )
335
380
. catch ( console . error ) ;
381
+ localDataChannel = clientLocal . createDataChannel ( "data" ) ;
382
+ } ;
383
+
384
+ const send = ( ) => {
385
+ if ( localDataChannel . readyState === "open" ) {
386
+ localDataChannel . send ( localData . value ) ;
387
+ }
336
388
} ;
337
389
338
390
let remoteStream ;
@@ -356,6 +408,12 @@ <h3>Pion</h3>
356
408
}
357
409
} ;
358
410
411
+ clientRemote . ondatachannel = ( { channel } ) => {
412
+ channel . onmessage = ( { data } ) => {
413
+ remoteData . innerHTML = data ;
414
+ } ;
415
+ } ;
416
+
359
417
const api = {
360
418
streamId : "" ,
361
419
video : "high" ,
0 commit comments