Skip to content

Latest commit

 

History

History
113 lines (102 loc) · 4.37 KB

demo.md

File metadata and controls

113 lines (102 loc) · 4.37 KB
layout title
page
Demo video chat · RoomRTC

{% raw %}

Connecting to: demo...

You are in room: demo

 

Display list clients

  • {{ $index + 1 }}: [{{ id }},{{ client.name }}]
{% endraw %} <script src="{{ site.baseurl }}/latest/roomrtc.bundle.js"></script> <script src="{{ site.baseurl }}/latest/angular-v1.4.9.js"></script> <script type="text/javascript"> angular.module("demo", []) .controller("roomController", function ($scope, $timeout, $sce) { $scope.localVideo = null; $scope.remoteVideos = {}; $scope.isConnected = false; var room = $scope.room = (location.search && location.search.split('?')[1]) || "demo"; var roomrtc = new RoomRTC(); roomrtc.initMediaSource() .then(stream => { var streamUrl = roomrtc.getStreamAsUrl(stream); $timeout(function () { $scope.localVideo = $sce.trustAsResourceUrl(streamUrl); }); }) .catch(err => { console.error('Failed to get local stream', err); }); roomrtc.on("connected", function (id) { console.log("connected connectionId: ", id); roomrtc.joinRoom(room) .then(roomData => { console.log("joinRoom ok: ", roomData); $timeout(function () { $scope.isConnected = true; $scope.clients = roomData.clients; }); return roomData.clients; }) .catch(err => { console.error("joinRoom error: ", err); }); }); roomrtc.on("readyToCall", function (id) { console.log("readyToCall, connectionId: ", id); }); roomrtc.on("videoAdded", function(pc, stream) { var pid = pc.id; console.log("Ohh, we have a new participant", pid); $timeout(function() { var streamUrl = roomrtc.getStreamAsUrl(stream); var trustUrl = $sce.trustAsResourceUrl(streamUrl); $scope.remoteVideos[pid] = trustUrl; $scope.clients[pid] = pc.resources; }) }); roomrtc.on("videoRemoved", function(pc) { var pid = pc.id; var url = $scope.remoteVideos[pid]; roomrtc.revokeObjectURL(url); console.log("Ohh, a participant has gone", pid); $timeout(function() { // remove url from remoteVideos delete $scope.remoteVideos[pid]; delete $scope.clients[pid]; }) }); /** * Setup control buttons * */ $scope.stop = function () { $scope.localVideo = null; roomrtc.stop(); } $scope.start = function () { roomrtc.initMediaSource().then(stream => { var streamUrl = roomrtc.getStreamAsUrl(stream); $timeout(function () { $scope.localVideo = $sce.trustAsResourceUrl(streamUrl); }); }); } }); </script>