Browse Source

support external SFU

Dele Olajide 3 năm trước cách đây
mục cha
commit
6a9d9d745a

+ 4 - 3
packages/galene/galene-socket.js

@@ -1,9 +1,10 @@
 class GaleneSocket
 {
-    constructor(connection) {
+    constructor(connection, host) {
 		this.OPEN = connection.connected;
 		this.connection = connection;	
 		this.readyState = this.OPEN;
+		this.host = host;
 		
 		this.connection.addHandler((iq) => {
 			const json_ele = iq.querySelector("json");
@@ -25,14 +26,14 @@ class GaleneSocket
 	close(code, reason) {
 		console.debug('GaleneSocket close', code, reason);
 
-		this.connection.sendIQ($iq({type: 'set', to: this.connection.domain}).c('c2s', {xmlns: 'urn:xmpp:sfu:galene:0'}), (res) => {
+		this.connection.sendIQ($iq({type: 'set', to: this.host}).c('c2s', {xmlns: 'urn:xmpp:sfu:galene:0'}), (res) => {
 			if (this.onclose) this.onclose({code, reason});		
 		});	
 	}
 	
 	send(text) {
 		console.debug('GaleneSocket send', text);			
-		this.connection.sendIQ($iq({type: 'set', to: this.connection.domain}).c('c2s', {xmlns: 'urn:xmpp:sfu:galene:0'}).c('json', {xmlns: 'urn:xmpp:json:0'}).t(text), (res) => {
+		this.connection.sendIQ($iq({type: 'set', to: this.host}).c('c2s', {xmlns: 'urn:xmpp:sfu:galene:0'}).c('json', {xmlns: 'urn:xmpp:json:0'}).t(text), (res) => {
 			//console.debug('GaleneSocket send response', res);	
 		});			
 	}

+ 4 - 4
packages/galene/galene-ui.js

@@ -3935,8 +3935,8 @@ window.onload = async function() {
     serverConnection.onchat = addToChatbox;
     serverConnection.onusermessage = gotUserMessage;
 
-	const username = urlParam("username");
-    const jid = username + "@localhost";
+	const host = urlParam("host");
+	const username = urlParam("username");	
     const password = "Welcome123";
 	
 	group = "public/" + urlParam("group");	
@@ -3945,10 +3945,10 @@ window.onload = async function() {
     setMediaChoices(false).then(e => reflectSettings());	
 
     const connection = window.top?.connection;
-	console.debug("onload", connection);	
+	console.debug("onload", connection, host, username);	
 	
 	if (connection) {
-		await serverConnection.connect(connection);
+		await serverConnection.connect(connection, host);
 		setViewportHeight();			
 	}
 }

+ 2 - 1
packages/galene/galene.js

@@ -30,6 +30,7 @@
             _converse.api.settings.update({
                 galene_head_display_toggle: false,
                 galene_signature: 'GALENE',
+				galene_host: 'pade.chat'
             });
 
             galene_confirm  = __('Galene Meeting?');
@@ -350,7 +351,7 @@
                 };
                 galeneFrame.__jid = jid;
                 galeneFrame.addEventListener("load", galeneIframeCloseHandler);
-                galeneFrame.setAttribute("src", "./packages/galene/index.html?username=" + Strophe.getNodeFromJid(_converse.connection.jid) + "&password=&group=" + room);
+                galeneFrame.setAttribute("src", "./packages/galene/index.html?username=" + Strophe.getNodeFromJid(_converse.connection.jid) + "&password=&group=" + room + "&host=" + _converse.api.settings.get("galene_host"));
                 galeneFrame.setAttribute("class", "galene");
                 galeneFrame.setAttribute("allow", "microphone; camera;");
                 galeneFrame.setAttribute("frameborder", "0");

+ 4 - 4
packages/galene/protocol.js

@@ -257,14 +257,14 @@ ServerConnection.prototype.send = function(m) {
  * @returns {Promise<ServerConnection>}
  * @function
  */
-ServerConnection.prototype.connect = async function(connection) {
+ServerConnection.prototype.connect = async function(connection, host) {
     let sc = this;
     if(sc.socket) {
         sc.socket.close(1000, 'Reconnecting');
         sc.socket = null;
     }
 
-    sc.socket = new GaleneSocket(connection);
+    sc.socket = new GaleneSocket(connection, host);
 
     return await new Promise((resolve, reject) => {
         this.socket.onerror = function(e) {
@@ -298,8 +298,8 @@ ServerConnection.prototype.connect = async function(connection) {
                 sc.onjoined.call(sc, 'leave', sc.group, [], {}, {}, '');
             sc.group = null;
             sc.username = null;
-            //if(sc.onclose)
-            //   sc.onclose.call(sc, e.code, e.reason);
+            if(sc.onclose)
+                sc.onclose.call(sc, e.code, e.reason);
             reject(new Error('websocket close ' + e.code + ' ' + e.reason));
         };
         this.socket.onmessage = function(e) {