From c35f286faddce304a506b3642eb61067197a59ed Mon Sep 17 00:00:00 2001 From: Moe Alam Date: Sun, 27 Sep 2020 22:14:36 -0700 Subject: [PATCH] cleaner connection to p2p --- libs/commander/worker.js | 26 ++++++++++++++------------ web/libs/js/dash2.config.js | 1 + web/libs/js/dash2.socketio.js | 25 ++++++++++++++----------- web/pages/blocks/header.ejs | 1 - 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/libs/commander/worker.js b/libs/commander/worker.js index 626dd7bb..54497c9d 100644 --- a/libs/commander/worker.js +++ b/libs/commander/worker.js @@ -117,18 +117,18 @@ const initialize = (config,lang) => { }) }) }) - const masterConnectionToMachine = createShinobiSocketConnection() - masterConnectionToMachine.on('connect', () => { - masterConnectionToMachine.emit('f',{ - f: 'init', - auth: config.p2pTargetAuth, - ke: config.p2pTargetGroupId, - uid: config.p2pTargetUserId - }) - }) - masterConnectionToMachine.on('f',(data) => { - connectionToP2PServer.emit('f',data) - }) + // const masterConnectionToMachine = createShinobiSocketConnection() + // masterConnectionToMachine.on('connect', () => { + // masterConnectionToMachine.emit('f',{ + // f: 'init', + // auth: config.p2pTargetAuth, + // ke: config.p2pTargetGroupId, + // uid: config.p2pTargetUserId + // }) + // }) + // masterConnectionToMachine.on('f',(data) => { + // connectionToP2PServer.emit('f',data) + // }) connectionToP2PServer.on('wsInit',(rawRequest) => { s.debugLog('p2pWsInit',rawRequest) @@ -195,6 +195,7 @@ const initialize = (config,lang) => { clientConnectionToMachine.emit(target,initData) }); clientConnectionToMachine.on('data',(data) => { + console.log(target) connectionToP2PServer.emit('data',{data: data, cnid: initData.cnid}) }); }else{ @@ -203,6 +204,7 @@ const initialize = (config,lang) => { }) }); connectionToP2PServer.on('wsDestroyStream',(clientKey) => { + console.log('wsDestroyStream',clientKey) if(p2pClientConnections[clientKey]){ p2pClientConnections[clientKey].disconnect(); } diff --git a/web/libs/js/dash2.config.js b/web/libs/js/dash2.config.js index a4501bed..76352beb 100644 --- a/web/libs/js/dash2.config.js +++ b/web/libs/js/dash2.config.js @@ -6,6 +6,7 @@ $.ccio={ libURL: location.search === '?p2p=1' ? location.pathname + '/' : '<%-window.libURL%>', isAppleDevice: navigator.userAgent.match(/(iPod|iPhone|iPad)/)||(navigator.userAgent.match(/(Safari)/)&&!navigator.userAgent.match('Chrome')) }; +window.machineId = location.pathname.split('/')[2] <% if(config.DropboxAppKey){ %> $.ccio.DropboxAppKey = '<%-window.DropboxAppKey%>' <% } %> diff --git a/web/libs/js/dash2.socketio.js b/web/libs/js/dash2.socketio.js index cf17a902..8ad08762 100644 --- a/web/libs/js/dash2.socketio.js +++ b/web/libs/js/dash2.socketio.js @@ -290,7 +290,7 @@ $.ccio.globalWebsocket=function(d,user){ if($.ccio.mon[d.ke+d.id+user.auth_token].Base64 && $.ccio.mon[d.ke+d.id+user.auth_token].Base64.connected){ $.ccio.mon[d.ke+d.id+user.auth_token].Base64.disconnect() } - $.ccio.mon[d.ke+d.id+user.auth_token].Base64 = io(location.origin,{ path: path, transports: ['websocket'], forceNew: false}) + $.ccio.mon[d.ke+d.id+user.auth_token].Base64 = io(location.origin,{ path: websocketPath, query: websocketQuery, transports: ['websocket'], forceNew: false}) var ws = $.ccio.mon[d.ke+d.id+user.auth_token].Base64 var buffer ws.on('diconnect',function(){ @@ -369,7 +369,8 @@ $.ccio.globalWebsocket=function(d,user){ uid:user.uid, id:d.id, url: location.origin, - path: path, + path: websocketPath, + query: websocketQuery, onError : onPoseidonError }) $.ccio.mon[d.ke+d.id+user.auth_token].Poseidon.start(); @@ -407,7 +408,8 @@ $.ccio.globalWebsocket=function(d,user){ maxLatency:d.d.stream_flv_maxLatency, hasAudio:false, url: location.origin, - path: path + path: websocketPath, + query: websocketQuery } }else{ options = { @@ -501,7 +503,7 @@ $.ccio.globalWebsocket=function(d,user){ $.ccio.mon[d.ke+d.id+user.auth_token].h265HttpStream.abort() } if(d.d.stream_flv_type==='ws'){ - $.ccio.mon[d.ke+d.id+user.auth_token].h265Socket = io(location.origin,{ path: path, transports: ['websocket'], forceNew: false}) + $.ccio.mon[d.ke+d.id+user.auth_token].h265Socket = io(location.origin,{ path: websocketPath, query: websocketQuery, transports: ['websocket'], forceNew: false}) var ws = $.ccio.mon[d.ke+d.id+user.auth_token].h265Socket ws.on('diconnect',function(){ console.log('h265Socket Stream Disconnected') @@ -689,15 +691,16 @@ $.ccio.globalWebsocket=function(d,user){ break; } } +var websocketPath = tool.checkCorrectPathEnding(location.pathname) + 'socket.io' +var websocketQuery = {} if(location.search === '?p2p=1'){ - $user.ws=io(location.origin,{ - path : '/socket.io' - }); -}else{ - $user.ws=io(location.origin,{ - path : tool.checkCorrectPathEnding(location.pathname)+'socket.io' - }); + websocketPath = '/socket.io' + websocketQuery.machineId = machineId } +$user.ws=io(location.origin,{ + path: websocketPath, + query: websocketQuery +}); $user.ws.on('connect',function (d){ $(document).ready(function(e){ $.ccio.init('id',$user); diff --git a/web/pages/blocks/header.ejs b/web/pages/blocks/header.ejs index d31563ce..c4d71467 100644 --- a/web/pages/blocks/header.ejs +++ b/web/pages/blocks/header.ejs @@ -22,4 +22,3 @@ if(!string){string=''} return string.replace(/'/g,"\\'") }%> -