Updated example for a simple video “conference”.
Things are going slow, but going.
Here’s an updated sample for the library which demonstrates the key parts of “getting chatting”.
Later on, when i have enough time, i’ll post an sample on howto tie all together with Nginx,
Flask and Upstart
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | import 'dart:html'; import 'package:dart_rtc_common/rtc_common.dart'; import 'package:dart_rtc_client/rtc_client.dart'; const int RECONNECT_MS = 10000; const String MYCHANNEL = "abc"; const String CONNECTION_STRING = "ws://127.0.0.1:8234/ws"; /** * WebRTC video "conference" sample */ void main() { /** * DataSource connects to the signaling server */ DataSource src = new WebSocketDataSource(CONNECTION_STRING); /** * ChannelClient accepts on parameter, which is the data source. */ ChannelClient client = new ChannelClient(src) //.setChannel(MYCHANNEL) // Setting channel here sets the client to join the channel on connect .setRequireAudio(true) // Microphone required .setRequireVideo(true) // Webcam or some other video source required .setRequireDataChannel(false) // Set true if you want to send data over data channels .setAutoCreatePeer(true); // If true, creates peerconnection automicly when joining a channel /** * Client sets states, in this callback you can track the state changes * and do actions when required */ client.onInitializationStateChangeEvent.listen((InitializationStateEvent e) { if (e.state == InitializationState.LOCAL_READY) { // Client has initialized local, not connected to the signaling server yet. } if (e.state == InitializationState.MEDIA_READY) { // Your local video stream is ready } if (e.state == InitializationState.REMOTE_READY) { // If you did not use .setChannel above, this is where you can join channel (Or later on if you so wish) client.joinChannel(MYCHANNEL); } if (e.state == InitializationState.CHANNEL_READY) { // Channel has been joined. // Setting channel limit to 2, which means that only 2 persons are able to join the channel. client.setChannelLimit(2); } }); /** * Client has connected to the server */ client.onSignalingOpenEvent.listen((SignalingOpenEvent e) { }); /** * MediaStream available events * Event name subject to change to onMediaStreamAvailableEvent * since this carries also local media stream event */ client.onRemoteMediaStreamAvailableEvent.listen((MediaStreamAvailableEvent e) { // Event contains a reference to PeerWrapper (e.peerWrapper) which has an id property // Usefull for tracking created video elements for example. // set the video element id to peerwrapper id. if (e.isLocal) { LocalMediaStream localStream = e.stream; // Do what is needed with your local media stream // someVideoElement.src = Url.createObjectUrl(localStream); // someVideoElement.play(); } else { MediaStream remoteStream = e.stream; // Do what is needed with your local media stream // someOtherVideoElement.src = Url.createObjectUrl(remoteStream); // someOtherVideoElement.play(); } }); /** * MediaStream removed events */ client.onRemoteMediaStreamRemovedEvent.listen((MediaStreamRemovedEvent e) { // Remove the video element created earlier // If you used the e.peerWrapper.id as an id to the video element // you can use that again to find the element and remove it. }); /** * Callback for when you loose connection to the server */ client.onSignalingCloseEvent.listen((SignalingCloseEvent e) { window.setTimeout(() { client.initialize(); }, RECONNECT_MS); }); client.initialize(); } |
Pingback: » Simple video example Sami @ Somewhere