rtc

minimal webrtc client
git clone git://ce9e.org/rtc

commit
6d3a016de7ada4eb291bb326f40e97763922fc7b
parent
5dd3445cc397435b60607cca1e6dd67faa99c7d6
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2020-03-26 10:37
pass key instead of url to signalling

Diffstat

M www/chat/chat.js 2 +-
M www/patch.js 11 ++++++-----
M www/rtc/rtc.js 20 ++++++++++----------

3 files changed, 17 insertions, 16 deletions


diff --git a/www/chat/chat.js b/www/chat/chat.js

@@ -1,7 +1,7 @@
    1     1 (function() {
    2     2 	// TODO: nicks
    3     3 
    4    -1 	var url = 'https://patchbay.pub/pubsub/' + location.hash.substr(1);
   -1     4 	var url = location.hash.substr(1);
    5     5 
    6     6 	var history = document.querySelector('.history');
    7     7 	var form = document.querySelector('.form');

diff --git a/www/patch.js b/www/patch.js

@@ -1,5 +1,6 @@
    1     1 (function() {
    2     2 	var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
   -1     3 	var baseUrl = 'https://patchbay.pub/pubsub/';
    3     4 
    4     5 	var randomString = function(length) {
    5     6 		var result = [];
@@ -14,14 +15,14 @@
   14    15 		location.hash = randomString(10);
   15    16 	}
   16    17 
   17    -1 	var post = function(url, data) {
   18    -1 		return fetch(url, {method: 'POST', body: JSON.stringify(data)});
   -1    18 	var post = function(key, data) {
   -1    19 		return fetch(baseUrl + key, {method: 'POST', body: JSON.stringify(data)});
   19    20 	};
   20    21 
   21    22 	// FIXME: prefer server send events
   22    -1 	var listen = function(url, fn) {
   23    -1 		p = fetch(url);
   24    -1 		p.finally(() => listen(url, fn));
   -1    23 	var listen = function(key, fn) {
   -1    24 		p = fetch(baseUrl + key);
   -1    25 		p.finally(() => listen(key, fn));
   25    26 		return p
   26    27 			.then(r => r.text())
   27    28 			.then(data => fn(data && JSON.parse(data)))

diff --git a/www/rtc/rtc.js b/www/rtc/rtc.js

@@ -5,9 +5,9 @@
    5     5 	// ICE -- networking information
    6     6 	// offer/answer -- media stream information
    7     7 
    8    -1 	var roomUrl = 'https://patchbay.pub/pubsub/' + location.hash.substr(1);
    9    -1 	var queueUrl = 'https://patchbay.pub/queue/' + patch.randomString(10);
   10    -1 	console.log('own queue', queueUrl);
   -1     8 	var room = location.hash.substr(1);
   -1     9 	var queue = patch.randomString(10);
   -1    10 	console.log('own queue', queue);
   11    11 
   12    12 	var container = document.querySelector('.videos');
   13    13 	var cons = {};
@@ -28,7 +28,7 @@
   28    28 			iceServers: [{urls: 'stun:stun.l.google.com:19302'}]
   29    29 		});
   30    30 		con.addEventListener('icecandidate', function(event) {
   31    -1 			patch.post(sender, {'sender': queueUrl, 'data': event.candidate});
   -1    31 			patch.post(sender, {'sender': queue, 'data': event.candidate});
   32    32 		});
   33    33 		con.addEventListener('negotiationneeded', function() {
   34    34 			makeOffer(sender);
@@ -60,11 +60,11 @@
   60    60 	};
   61    61 
   62    62 	var makeOffer = function(sender) {
   63    -1 		if (sender !== queueUrl) {
   -1    63 		if (sender !== queue) {
   64    64 			var con = getConnection(sender);
   65    65 			con.createOffer().then(offer => {
   66    66 				con.setLocalDescription(offer).then(_ => {
   67    -1 					patch.post(sender, {'sender': queueUrl, 'data': offer});
   -1    67 					patch.post(sender, {'sender': queue, 'data': offer});
   68    68 				});
   69    69 			});
   70    70 		}
@@ -75,7 +75,7 @@
   75    75 		con.setRemoteDescription(offer).then(_ => {
   76    76 			con.createAnswer().then(answer => {
   77    77 				con.setLocalDescription(answer).then(_ => {
   78    -1 					patch.post(sender, {'sender': queueUrl, 'data': answer});
   -1    78 					patch.post(sender, {'sender': queue, 'data': answer});
   79    79 				});
   80    80 			});
   81    81 		});
@@ -91,11 +91,11 @@
   91    91 		con.addIceCandidate(candidate);
   92    92 	};
   93    93 
   94    -1 	patch.listen(roomUrl, function(data) {
   -1    94 	patch.listen(room, function(data) {
   95    95 		makeOffer(data);
   96    96 	});
   97    97 
   98    -1 	patch.listen(queueUrl, function(data) {
   -1    98 	patch.listen(queue, function(data) {
   99    99 		var sender = data.sender;
  100   100 		var data = data.data;
  101   101 		if (sender && data) {
@@ -110,7 +110,7 @@
  110   110 		console.log('unknown message', data);
  111   111 	});
  112   112 
  113    -1 	patch.post(roomUrl, queueUrl);
   -1   113 	patch.post(room, queue);
  114   114 
  115   115 	var updateConnections = function() {
  116   116 		var sender, c;