rtc

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

commit
0612ba07d20f38165352a59e5152fac27afa8fe3
parent
1edbb7409fb6ccf10966a6eb68b4e6c1ea61881c
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2020-05-06 05:17
use lists for messages to reduce overhead

Diffstat

M static/chat.js 2 +-
M static/rtc.js 34 +++++++++++++++++-----------------

2 files changed, 18 insertions, 18 deletions


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

@@ -10,7 +10,7 @@ export var init = function(room, queue) {
   10    10 		if (!input.value) {
   11    11 			return;
   12    12 		}
   13    -1 		via.send(room, {sender: queue, type: 'chat', text: input.value}).then(function() {
   -1    13 		via.send(room, [queue, 'chat', input.value]).then(function() {
   14    14 			input.value = '';
   15    15 		});
   16    16 	});

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

@@ -46,7 +46,7 @@ var getConnection = function(sender) {
   46    46 		iceServers: [{urls: 'stun:ce9e.org:3478'}],
   47    47 	});
   48    48 	con.addEventListener('icecandidate', function(event) {
   49    -1 		via.send(sender, {sender: queue, type: 'candidate', data: event.candidate});
   -1    49 		via.send(sender, [queue, 'candidate', event.candidate]);
   50    50 	});
   51    51 	con.addEventListener('negotiationneeded', function() {
   52    52 		makeOffer(sender);
@@ -76,7 +76,7 @@ var makeOffer = function(sender) {
   76    76 		var con = getConnection(sender);
   77    77 		con.createOffer().then(offer => {
   78    78 			con.setLocalDescription(offer).then(() => {
   79    -1 				via.send(sender, {sender: queue, type: 'offer', data: offer});
   -1    79 				via.send(sender, [queue, 'offer', offer]);
   80    80 			});
   81    81 		});
   82    82 	}
@@ -87,7 +87,7 @@ var handleOffer = function(sender, offer) {
   87    87 	con.setRemoteDescription(offer).then(() => {
   88    88 		con.createAnswer().then(answer => {
   89    89 			con.setLocalDescription(answer).then(() => {
   90    -1 				via.send(sender, {sender: queue, type: 'answer', data: answer});
   -1    90 				via.send(sender, [queue, 'answer', answer]);
   91    91 			});
   92    92 		});
   93    93 	});
@@ -108,31 +108,31 @@ var handleCandidate = function(sender, candidate) {
  108   108 };
  109   109 
  110   110 via.listen(queue + ':' + queuePassword, function(msg) {
  111    -1 	if (msg.type === 'offer') {
  112    -1 		handleOffer(msg.sender, msg.data);
  113    -1 	} else if (msg.type === 'answer') {
  114    -1 		handleAnswer(msg.sender, msg.data);
  115    -1 	} else if (msg.type === 'candidate') {
  116    -1 		handleCandidate(msg.sender, msg.data);
   -1   111 	if (msg[1] === 'offer') {
   -1   112 		handleOffer(msg[0], msg[2]);
   -1   113 	} else if (msg[1] === 'answer') {
   -1   114 		handleAnswer(msg[0], msg[2]);
   -1   115 	} else if (msg[1] === 'candidate') {
   -1   116 		handleCandidate(msg[0], msg[2]);
  117   117 	} else {
  118   118 		console.log('unknown message', msg);
  119   119 	}
  120   120 });
  121   121 
  122   122 via.listen(room, function(msg) {
  123    -1 	if (msg.type === 'chat') {
  124    -1 		chat.addMsg(msg.sender, msg.text);
  125    -1 	} else if (msg.type === 'announce') {
  126    -1 		makeOffer(msg.sender);
  127    -1 	} else if (msg.type === 'leave') {
  128    -1 		closeConnection(msg.sender);
   -1   123 	if (msg[1] === 'chat') {
   -1   124 		chat.addMsg(msg[0], msg[2]);
   -1   125 	} else if (msg[1] === 'announce') {
   -1   126 		makeOffer(msg[0]);
   -1   127 	} else if (msg[1] === 'leave') {
   -1   128 		closeConnection(msg[0]);
  129   129 	} else {
  130   130 		console.log('unknown message', msg);
  131   131 	}
  132   132 });
  133   133 
  134   134 window.addEventListener('beforeunload', function() {
  135    -1 	via.send(room, {sender: queue, type: 'leave'}, true);
   -1   135 	via.send(room, [queue, 'leave'], true);
  136   136 });
  137   137 
  138   138 chat.init(room, queue);
@@ -148,4 +148,4 @@ media.init(function() {
  148   148 	}
  149   149 });
  150   150 
  151    -1 via.send(room, {sender: queue, type: 'announce'});
   -1   151 via.send(room, [queue, 'announce']);