webview.io 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/index.ts +47 -42
package/dist/index.js
CHANGED
|
@@ -679,7 +679,7 @@ var WIO = /** @class */ (function () {
|
|
|
679
679
|
* Sets up the EMBEDDED side of the bridge
|
|
680
680
|
*/
|
|
681
681
|
WIO.prototype.getInjectedJavaScript = function () {
|
|
682
|
-
return "\n (function() {\n try {\n console.log('[EMBEDDED] Initializing WIO bridge...')\n \n const RESERVED_EVENTS = [\n 'ping',\n 'pong',\n '__heartbeat',\n '__heartbeat_response',\n '__embedded_ready',\n '__connection_ack',\n '__webview_ready'\n ]\n \n // Use closure variable to avoid 'this' binding issues\n const wio = {\n type: 'EMBEDDED',\n connected: false,\n Events: {},\n messageQueue: [],\n connectionToken: null,\n setupComplete: false,\n\n listen: function(){\n console.log('[EMBEDDED] Setting up message listeners...')\n\n // Listen to messages from React Native\n window.addEventListener('message', function( event ){\n try {\n const message = typeof event.data === 'string' ? JSON.parse( event.data ) : event.data\n wio.handleMessage( message ) // Use wio instead of this\n }\n catch( error ){ console.error('[EMBEDDED] Parse error:', error ) }\n })\n \n // Android support\n if( typeof document !== 'undefined' ){\n document.addEventListener('message', function( event ){\n try {\n const message = typeof event.data === 'string' ? JSON.parse( event.data ) : event.data\n wio.handleMessage( message ) // Use wio instead of this\n }\n catch( error ){ console.error('[EMBEDDED] Parse error:', error ) }\n })\n }\n\n wio.setupComplete = true // Use wio instead of this\n console.log('[EMBEDDED] Setup complete')\n },\n \n ackId: function(){\n const\n rmin = 100000,\n rmax = 999999,\n timestamp = Date.now(),\n random = Math.floor( Math.random() * ( rmax - rmin + 1 ) + rmin )\n\n return timestamp + '_' + random\n },\n \n fire: function( _event, payload, cid ){\n if( !wio.Events[_event] && !wio.Events[_event + '--@once'] ){\n console.log('[EMBEDDED] No listener for:', _event)\n return\n }\n \n const ackFn = cid\n ? ( error, ...args ) => wio.emit( _event + '--' + cid + '--@ack', { error: error || false, args } )\n : undefined\n \n let listeners = []\n if( wio.Events[_event + '--@once'] ){\n _event += '--@once'\n listeners = wio.Events[_event]\n\n delete wio.Events[_event]\n }\n else listeners = wio.Events[_event] || []\n \n listeners.forEach( fn => {\n try { payload !== undefined ? fn( payload, ackFn ) : fn( ackFn ) }\n catch( error ){ console.error('[EMBEDDED] Listener error:', error ) }\n })\n },\n \n emit: function( _event, payload, fn ){\n if( typeof payload === 'function' ){\n fn = payload\n payload = undefined\n }\n \n if( !wio.connected && !RESERVED_EVENTS.includes(_event) ){\n wio.messageQueue.push({ _event, payload, fn, timestamp: Date.now() })\n console.log('[EMBEDDED] Queued message:', _event)\n return\n }\n \n try {\n let cid\n if( typeof fn === 'function' ){\n cid = wio.ackId()\n wio.once( _event + '--' + cid + '--@ack', ({ error, args }) => fn( error, ...args ) )\n }\n \n const messageData = {\n _event,\n payload,\n cid,\n timestamp: Date.now(),\n token: RESERVED_EVENTS.includes(_event) ? wio.connectionToken : undefined\n }\n \n if( typeof window.ReactNativeWebView !== 'undefined' )\n window.ReactNativeWebView.postMessage( JSON.stringify( messageData ) )\n else console.error('[EMBEDDED] ReactNativeWebView not available')\n }\n catch( error ){\n console.error('[EMBEDDED] Emit error:', error )\n typeof fn === 'function' && fn( String(error) )\n }\n },\n \n on: function( _event, fn ){\n if( !wio.Events[_event] ) wio.Events[_event] = []\n wio.Events[_event].push( fn )\n },\n \n once: function( _event, fn ){\n _event += '--@once'\n if( !wio.Events[_event] ) wio.Events[_event] = []\n\n wio.Events[_event].push( fn )\n },\n \n off: function( _event, fn ){\n if( fn && wio.Events[_event] ){\n const index = wio.Events[_event].indexOf( fn )\n if( index > -1 ){\n wio.Events[_event].splice( index, 1 )\n if( wio.Events[_event].length === 0 ) delete wio.Events[_event]\n }\n }\n else delete wio.Events[_event]\n },\n \n processMessageQueue: function(){\n if( !wio.connected || wio.messageQueue.length === 0 ) return\n \n console.log('[EMBEDDED] Processing', wio.messageQueue.length, 'queued messages')\n const queue = [ ...wio.messageQueue ]\n wio.messageQueue = []\n \n queue.forEach( msg => {\n try { wio.emit( msg._event, msg.payload, msg.fn ) }\n catch( error ){ console.error('[EMBEDDED] Queue process error:', error ) }\n })\n },\n \n handleMessage: function( data ){\n if( !data || !data._event ) return\n \n const { _event, payload, cid, token } = data\n \n console.log('[EMBEDDED] Received:', _event )\n \n // Handle heartbeat response\n if( _event === '__heartbeat_response' )\n return\n \n // Handle heartbeat request\n if( _event === '__heartbeat' ){\n wio.emit('__heartbeat_response', { timestamp: Date.now() })\n return\n }\n \n // Handle webview ready signal\n if( _event === '__webview_ready' ){\n console.log('[EMBEDDED] WebView ready signal received')\n return\n }\n \n // Handle ping from WEBVIEW\n if( _event === 'ping' ){\n console.log('[EMBEDDED] Received ping, sending pong')\n wio.connectionToken = token\n\n wio.emit('pong', { token: wio.connectionToken })\n return\n }\n \n // Handle connection acknowledgment\n if( _event === '__connection_ack' ){\n if( token && token !== wio.connectionToken ){\n console.error('[EMBEDDED] Invalid connection token in ack')\n return\n }\n \n console.log('[EMBEDDED] Connection established (received ack)')\n\n wio.connected = true\n wio.processMessageQueue()\n wio.fire('connect')\n\n return\n }\n \n // Fire event listeners\n wio.fire( _event, payload, cid )\n },\n \n announceReady: function(){\n let attempts = 0\n const maxAttempts = 5\n const interval = 2000\n \n console.log('[EMBEDDED] Starting ready announcements')\n \n const announce = () => {\n if( wio.connected ){\n console.log('[EMBEDDED] Connected, stopping announcements')\n return\n }\n \n attempts++\n if( attempts > maxAttempts ){\n console.log('[EMBEDDED] Max announcement attempts reached')\n return\n }\n \n console.log('[EMBEDDED] Announcing ready (attempt', attempts + '/' + maxAttempts + ')')\n wio.emit('__embedded_ready')\n \n setTimeout( announce, interval )\n }\n \n announce()\n }\n }\n\n // Expose to global scope\n window._wio = wio\n\n // Initialize\n wio.listen()\n // Start announcing readiness after a short delay\n setTimeout(() => wio.announceReady(), 100)\n \n console.log('[EMBEDDED] WIO bridge initialized successfully')\n }\n catch( error ){\n console.error('[EMBEDDED] Setup failed:', error )\n \n // Create minimal fallback\n window._wio = {\n error: error.toString(),\n emit: function(){ console.error('[EMBEDDED] WIO failed to initialize') },\n on: function(){},\n once: function(){},\n off: function(){}\n }\n }\n\n true\n })()\n ";
|
|
682
|
+
return "\n (function() {\n try {\n console.log('[EMBEDDED] Initializing WIO bridge...')\n \n const RESERVED_EVENTS = [\n 'ping',\n 'pong',\n '__heartbeat',\n '__heartbeat_response',\n '__embedded_ready',\n '__connection_ack',\n '__webview_ready'\n ]\n \n // Use closure variable to avoid 'this' binding issues\n window._wio = {\n type: 'EMBEDDED',\n connected: false,\n Events: {},\n messageQueue: [],\n connectionToken: null,\n setupComplete: false,\n\n listen: function(){\n console.log('[EMBEDDED] Setting up message listeners...')\n\n // Listen to messages from React Native\n window.addEventListener('message', function( event ){\n try {\n const message = typeof event.data === 'string' ? JSON.parse( event.data ) : event.data\n window._wio.handleMessage( message ) // Use window._wio instead of this\n }\n catch( error ){ console.error('[EMBEDDED] Parse error:', error ) }\n })\n \n // Android support\n if( typeof document !== 'undefined' ){\n document.addEventListener('message', function( event ){\n try {\n const message = typeof event.data === 'string' ? JSON.parse( event.data ) : event.data\n window._wio.handleMessage( message ) // Use window._wio instead of this\n }\n catch( error ){ console.error('[EMBEDDED] Parse error:', error ) }\n })\n }\n\n window._wio.setupComplete = true // Use window._wio instead of this\n console.log('[EMBEDDED] Setup complete')\n\n return window._wio\n },\n \n ackId: function(){\n const\n rmin = 100000,\n rmax = 999999,\n timestamp = Date.now(),\n random = Math.floor( Math.random() * ( rmax - rmin + 1 ) + rmin )\n\n return timestamp + '_' + random\n },\n \n fire: function( _event, payload, cid ){\n if( !window._wio.Events[_event] && !window._wio.Events[_event + '--@once'] ){\n console.log('[EMBEDDED] No listener for:', _event)\n return\n }\n \n const ackFn = cid\n ? ( error, ...args ) => window._wio.emit( _event + '--' + cid + '--@ack', { error: error || false, args } )\n : undefined\n \n let listeners = []\n if( window._wio.Events[_event + '--@once'] ){\n _event += '--@once'\n listeners = window._wio.Events[_event]\n\n delete window._wio.Events[_event]\n }\n else listeners = window._wio.Events[_event] || []\n \n listeners.forEach( fn => {\n try { payload !== undefined ? fn( payload, ackFn ) : fn( ackFn ) }\n catch( error ){ console.error('[EMBEDDED] Listener error:', error ) }\n })\n },\n \n emit: function( _event, payload, fn ){\n if( typeof payload === 'function' ){\n fn = payload\n payload = undefined\n }\n \n if( !window._wio.connected && !RESERVED_EVENTS.includes(_event) ){\n window._wio.messageQueue.push({ _event, payload, fn, timestamp: Date.now() })\n console.log('[EMBEDDED] Queued message:', _event)\n return\n }\n \n try {\n let cid\n if( typeof fn === 'function' ){\n cid = window._wio.ackId()\n window._wio.once( _event + '--' + cid + '--@ack', ({ error, args }) => fn( error, ...args ) )\n }\n \n const messageData = {\n _event,\n payload,\n cid,\n timestamp: Date.now(),\n token: RESERVED_EVENTS.includes(_event) ? window._wio.connectionToken : undefined\n }\n \n if( typeof window.ReactNativeWebView !== 'undefined' )\n window.ReactNativeWebView.postMessage( JSON.stringify( messageData ) )\n else console.error('[EMBEDDED] ReactNativeWebView not available')\n }\n catch( error ){\n console.error('[EMBEDDED] Emit error:', error )\n typeof fn === 'function' && fn( String(error) )\n }\n },\n \n on: function( _event, fn ){\n if( !window._wio.Events[_event] ) window._wio.Events[_event] = []\n window._wio.Events[_event].push( fn )\n\n return window._wio\n },\n \n once: function( _event, fn ){\n _event += '--@once'\n if( !window._wio.Events[_event] ) window._wio.Events[_event] = []\n\n window._wio.Events[_event].push( fn )\n\n return window._wio\n },\n \n off: function( _event, fn ){\n if( fn && window._wio.Events[_event] ){\n const index = window._wio.Events[_event].indexOf( fn )\n if( index > -1 ){\n window._wio.Events[_event].splice( index, 1 )\n if( window._wio.Events[_event].length === 0 ) delete window._wio.Events[_event]\n }\n }\n else delete window._wio.Events[_event]\n\n return window._wio\n },\n \n processMessageQueue: function(){\n if( !window._wio.connected || window._wio.messageQueue.length === 0 ) return\n \n console.log('[EMBEDDED] Processing', window._wio.messageQueue.length, 'queued messages')\n const queue = [ ...window._wio.messageQueue ]\n window._wio.messageQueue = []\n \n queue.forEach( msg => {\n try { window._wio.emit( msg._event, msg.payload, msg.fn ) }\n catch( error ){ console.error('[EMBEDDED] Queue process error:', error ) }\n })\n },\n \n handleMessage: function( data ){\n if( !data || !data._event ) return\n \n const { _event, payload, cid, token } = data\n \n console.log('[EMBEDDED] Received:', _event )\n \n // Handle heartbeat response\n if( _event === '__heartbeat_response' )\n return\n \n // Handle heartbeat request\n if( _event === '__heartbeat' ){\n window._wio.emit('__heartbeat_response', { timestamp: Date.now() })\n return\n }\n \n // Handle webview ready signal\n if( _event === '__webview_ready' ){\n console.log('[EMBEDDED] WebView ready signal received')\n return\n }\n \n // Handle ping from WEBVIEW\n if( _event === 'ping' ){\n console.log('[EMBEDDED] Received ping, sending pong')\n window._wio.connectionToken = token\n\n window._wio.emit('pong', { token: window._wio.connectionToken })\n return\n }\n \n // Handle connection acknowledgment\n if( _event === '__connection_ack' ){\n if( token && token !== window._wio.connectionToken ){\n console.error('[EMBEDDED] Invalid connection token in ack')\n return\n }\n \n console.log('[EMBEDDED] Connection established (received ack)')\n\n window._wio.connected = true\n window._wio.processMessageQueue()\n window._wio.fire('connect')\n\n return\n }\n \n // Fire event listeners\n window._wio.fire( _event, payload, cid )\n },\n \n announceReady: function(){\n let attempts = 0\n const maxAttempts = 5\n const interval = 2000\n \n console.log('[EMBEDDED] Starting ready announcements')\n \n const announce = () => {\n if( window._wio.connected ){\n console.log('[EMBEDDED] Connected, stopping announcements')\n return\n }\n \n attempts++\n if( attempts > maxAttempts ){\n console.log('[EMBEDDED] Max announcement attempts reached')\n return\n }\n \n console.log('[EMBEDDED] Announcing ready (attempt', attempts + '/' + maxAttempts + ')')\n window._wio.emit('__embedded_ready')\n \n setTimeout( announce, interval )\n }\n \n announce()\n }\n }\n\n // Initialize\n wio.listen()\n // Start announcing readiness after a short delay\n setTimeout(() => wio.announceReady(), 100)\n \n console.log('[EMBEDDED] WIO bridge initialized successfully')\n }\n catch( error ){\n console.error('[EMBEDDED] Setup failed:', error )\n \n // Create minimal fallback\n window._wio = {\n error: error.toString(),\n emit: function(){ console.error('[EMBEDDED] WIO failed to initialize') },\n on: function(){},\n once: function(){},\n off: function(){}\n }\n }\n\n true\n })()\n ";
|
|
683
683
|
};
|
|
684
684
|
return WIO;
|
|
685
685
|
}());
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "webview.io",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Easy and friendly API to connect and interact between React Native and WebView with enhanced security, reliability, and modern async/await support.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
package/src/index.ts
CHANGED
|
@@ -840,7 +840,7 @@ export default class WIO {
|
|
|
840
840
|
]
|
|
841
841
|
|
|
842
842
|
// Use closure variable to avoid 'this' binding issues
|
|
843
|
-
|
|
843
|
+
window._wio = {
|
|
844
844
|
type: 'EMBEDDED',
|
|
845
845
|
connected: false,
|
|
846
846
|
Events: {},
|
|
@@ -855,7 +855,7 @@ export default class WIO {
|
|
|
855
855
|
window.addEventListener('message', function( event ){
|
|
856
856
|
try {
|
|
857
857
|
const message = typeof event.data === 'string' ? JSON.parse( event.data ) : event.data
|
|
858
|
-
|
|
858
|
+
window._wio.handleMessage( message ) // Use window._wio instead of this
|
|
859
859
|
}
|
|
860
860
|
catch( error ){ console.error('[EMBEDDED] Parse error:', error ) }
|
|
861
861
|
})
|
|
@@ -865,14 +865,16 @@ export default class WIO {
|
|
|
865
865
|
document.addEventListener('message', function( event ){
|
|
866
866
|
try {
|
|
867
867
|
const message = typeof event.data === 'string' ? JSON.parse( event.data ) : event.data
|
|
868
|
-
|
|
868
|
+
window._wio.handleMessage( message ) // Use window._wio instead of this
|
|
869
869
|
}
|
|
870
870
|
catch( error ){ console.error('[EMBEDDED] Parse error:', error ) }
|
|
871
871
|
})
|
|
872
872
|
}
|
|
873
873
|
|
|
874
|
-
|
|
874
|
+
window._wio.setupComplete = true // Use window._wio instead of this
|
|
875
875
|
console.log('[EMBEDDED] Setup complete')
|
|
876
|
+
|
|
877
|
+
return window._wio
|
|
876
878
|
},
|
|
877
879
|
|
|
878
880
|
ackId: function(){
|
|
@@ -886,23 +888,23 @@ export default class WIO {
|
|
|
886
888
|
},
|
|
887
889
|
|
|
888
890
|
fire: function( _event, payload, cid ){
|
|
889
|
-
if( !
|
|
891
|
+
if( !window._wio.Events[_event] && !window._wio.Events[_event + '--@once'] ){
|
|
890
892
|
console.log('[EMBEDDED] No listener for:', _event)
|
|
891
893
|
return
|
|
892
894
|
}
|
|
893
895
|
|
|
894
896
|
const ackFn = cid
|
|
895
|
-
? ( error, ...args ) =>
|
|
897
|
+
? ( error, ...args ) => window._wio.emit( _event + '--' + cid + '--@ack', { error: error || false, args } )
|
|
896
898
|
: undefined
|
|
897
899
|
|
|
898
900
|
let listeners = []
|
|
899
|
-
if(
|
|
901
|
+
if( window._wio.Events[_event + '--@once'] ){
|
|
900
902
|
_event += '--@once'
|
|
901
|
-
listeners =
|
|
903
|
+
listeners = window._wio.Events[_event]
|
|
902
904
|
|
|
903
|
-
delete
|
|
905
|
+
delete window._wio.Events[_event]
|
|
904
906
|
}
|
|
905
|
-
else listeners =
|
|
907
|
+
else listeners = window._wio.Events[_event] || []
|
|
906
908
|
|
|
907
909
|
listeners.forEach( fn => {
|
|
908
910
|
try { payload !== undefined ? fn( payload, ackFn ) : fn( ackFn ) }
|
|
@@ -916,8 +918,8 @@ export default class WIO {
|
|
|
916
918
|
payload = undefined
|
|
917
919
|
}
|
|
918
920
|
|
|
919
|
-
if( !
|
|
920
|
-
|
|
921
|
+
if( !window._wio.connected && !RESERVED_EVENTS.includes(_event) ){
|
|
922
|
+
window._wio.messageQueue.push({ _event, payload, fn, timestamp: Date.now() })
|
|
921
923
|
console.log('[EMBEDDED] Queued message:', _event)
|
|
922
924
|
return
|
|
923
925
|
}
|
|
@@ -925,8 +927,8 @@ export default class WIO {
|
|
|
925
927
|
try {
|
|
926
928
|
let cid
|
|
927
929
|
if( typeof fn === 'function' ){
|
|
928
|
-
cid =
|
|
929
|
-
|
|
930
|
+
cid = window._wio.ackId()
|
|
931
|
+
window._wio.once( _event + '--' + cid + '--@ack', ({ error, args }) => fn( error, ...args ) )
|
|
930
932
|
}
|
|
931
933
|
|
|
932
934
|
const messageData = {
|
|
@@ -934,7 +936,7 @@ export default class WIO {
|
|
|
934
936
|
payload,
|
|
935
937
|
cid,
|
|
936
938
|
timestamp: Date.now(),
|
|
937
|
-
token: RESERVED_EVENTS.includes(_event) ?
|
|
939
|
+
token: RESERVED_EVENTS.includes(_event) ? window._wio.connectionToken : undefined
|
|
938
940
|
}
|
|
939
941
|
|
|
940
942
|
if( typeof window.ReactNativeWebView !== 'undefined' )
|
|
@@ -948,37 +950,43 @@ export default class WIO {
|
|
|
948
950
|
},
|
|
949
951
|
|
|
950
952
|
on: function( _event, fn ){
|
|
951
|
-
if( !
|
|
952
|
-
|
|
953
|
+
if( !window._wio.Events[_event] ) window._wio.Events[_event] = []
|
|
954
|
+
window._wio.Events[_event].push( fn )
|
|
955
|
+
|
|
956
|
+
return window._wio
|
|
953
957
|
},
|
|
954
958
|
|
|
955
959
|
once: function( _event, fn ){
|
|
956
960
|
_event += '--@once'
|
|
957
|
-
if( !
|
|
961
|
+
if( !window._wio.Events[_event] ) window._wio.Events[_event] = []
|
|
958
962
|
|
|
959
|
-
|
|
963
|
+
window._wio.Events[_event].push( fn )
|
|
964
|
+
|
|
965
|
+
return window._wio
|
|
960
966
|
},
|
|
961
967
|
|
|
962
968
|
off: function( _event, fn ){
|
|
963
|
-
if( fn &&
|
|
964
|
-
const index =
|
|
969
|
+
if( fn && window._wio.Events[_event] ){
|
|
970
|
+
const index = window._wio.Events[_event].indexOf( fn )
|
|
965
971
|
if( index > -1 ){
|
|
966
|
-
|
|
967
|
-
if(
|
|
972
|
+
window._wio.Events[_event].splice( index, 1 )
|
|
973
|
+
if( window._wio.Events[_event].length === 0 ) delete window._wio.Events[_event]
|
|
968
974
|
}
|
|
969
975
|
}
|
|
970
|
-
else delete
|
|
976
|
+
else delete window._wio.Events[_event]
|
|
977
|
+
|
|
978
|
+
return window._wio
|
|
971
979
|
},
|
|
972
980
|
|
|
973
981
|
processMessageQueue: function(){
|
|
974
|
-
if( !
|
|
982
|
+
if( !window._wio.connected || window._wio.messageQueue.length === 0 ) return
|
|
975
983
|
|
|
976
|
-
console.log('[EMBEDDED] Processing',
|
|
977
|
-
const queue = [ ...
|
|
978
|
-
|
|
984
|
+
console.log('[EMBEDDED] Processing', window._wio.messageQueue.length, 'queued messages')
|
|
985
|
+
const queue = [ ...window._wio.messageQueue ]
|
|
986
|
+
window._wio.messageQueue = []
|
|
979
987
|
|
|
980
988
|
queue.forEach( msg => {
|
|
981
|
-
try {
|
|
989
|
+
try { window._wio.emit( msg._event, msg.payload, msg.fn ) }
|
|
982
990
|
catch( error ){ console.error('[EMBEDDED] Queue process error:', error ) }
|
|
983
991
|
})
|
|
984
992
|
},
|
|
@@ -996,7 +1004,7 @@ export default class WIO {
|
|
|
996
1004
|
|
|
997
1005
|
// Handle heartbeat request
|
|
998
1006
|
if( _event === '__heartbeat' ){
|
|
999
|
-
|
|
1007
|
+
window._wio.emit('__heartbeat_response', { timestamp: Date.now() })
|
|
1000
1008
|
return
|
|
1001
1009
|
}
|
|
1002
1010
|
|
|
@@ -1009,30 +1017,30 @@ export default class WIO {
|
|
|
1009
1017
|
// Handle ping from WEBVIEW
|
|
1010
1018
|
if( _event === 'ping' ){
|
|
1011
1019
|
console.log('[EMBEDDED] Received ping, sending pong')
|
|
1012
|
-
|
|
1020
|
+
window._wio.connectionToken = token
|
|
1013
1021
|
|
|
1014
|
-
|
|
1022
|
+
window._wio.emit('pong', { token: window._wio.connectionToken })
|
|
1015
1023
|
return
|
|
1016
1024
|
}
|
|
1017
1025
|
|
|
1018
1026
|
// Handle connection acknowledgment
|
|
1019
1027
|
if( _event === '__connection_ack' ){
|
|
1020
|
-
if( token && token !==
|
|
1028
|
+
if( token && token !== window._wio.connectionToken ){
|
|
1021
1029
|
console.error('[EMBEDDED] Invalid connection token in ack')
|
|
1022
1030
|
return
|
|
1023
1031
|
}
|
|
1024
1032
|
|
|
1025
1033
|
console.log('[EMBEDDED] Connection established (received ack)')
|
|
1026
1034
|
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1035
|
+
window._wio.connected = true
|
|
1036
|
+
window._wio.processMessageQueue()
|
|
1037
|
+
window._wio.fire('connect')
|
|
1030
1038
|
|
|
1031
1039
|
return
|
|
1032
1040
|
}
|
|
1033
1041
|
|
|
1034
1042
|
// Fire event listeners
|
|
1035
|
-
|
|
1043
|
+
window._wio.fire( _event, payload, cid )
|
|
1036
1044
|
},
|
|
1037
1045
|
|
|
1038
1046
|
announceReady: function(){
|
|
@@ -1043,7 +1051,7 @@ export default class WIO {
|
|
|
1043
1051
|
console.log('[EMBEDDED] Starting ready announcements')
|
|
1044
1052
|
|
|
1045
1053
|
const announce = () => {
|
|
1046
|
-
if(
|
|
1054
|
+
if( window._wio.connected ){
|
|
1047
1055
|
console.log('[EMBEDDED] Connected, stopping announcements')
|
|
1048
1056
|
return
|
|
1049
1057
|
}
|
|
@@ -1055,7 +1063,7 @@ export default class WIO {
|
|
|
1055
1063
|
}
|
|
1056
1064
|
|
|
1057
1065
|
console.log('[EMBEDDED] Announcing ready (attempt', attempts + '/' + maxAttempts + ')')
|
|
1058
|
-
|
|
1066
|
+
window._wio.emit('__embedded_ready')
|
|
1059
1067
|
|
|
1060
1068
|
setTimeout( announce, interval )
|
|
1061
1069
|
}
|
|
@@ -1064,9 +1072,6 @@ export default class WIO {
|
|
|
1064
1072
|
}
|
|
1065
1073
|
}
|
|
1066
1074
|
|
|
1067
|
-
// Expose to global scope
|
|
1068
|
-
window._wio = wio
|
|
1069
|
-
|
|
1070
1075
|
// Initialize
|
|
1071
1076
|
wio.listen()
|
|
1072
1077
|
// Start announcing readiness after a short delay
|