diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/webrtc/library_godot_webrtc.js | 184 | ||||
-rw-r--r-- | modules/websocket/library_godot_websocket.js | 62 |
2 files changed, 123 insertions, 123 deletions
diff --git a/modules/webrtc/library_godot_webrtc.js b/modules/webrtc/library_godot_webrtc.js index c8a10018e5..3b2a8fe60c 100644 --- a/modules/webrtc/library_godot_webrtc.js +++ b/modules/webrtc/library_godot_webrtc.js @@ -32,7 +32,7 @@ const GodotRTCDataChannel = { // Our socket implementation that forwards events to C++. $GodotRTCDataChannel__deps: ['$IDHandler', '$GodotRuntime'], $GodotRTCDataChannel: { - connect: function(p_id, p_on_open, p_on_message, p_on_error, p_on_close) { + connect: function (p_id, p_on_open, p_on_message, p_on_error, p_on_close) { const ref = IDHandler.get(p_id); if (!ref) { return; @@ -48,31 +48,31 @@ const GodotRTCDataChannel = { ref.onerror = function (event) { p_on_error(); }; - ref.onmessage = function(event) { - var buffer; - var is_string = 0; + ref.onmessage = function (event) { + let buffer; + let is_string = 0; if (event.data instanceof ArrayBuffer) { buffer = new Uint8Array(event.data); } else if (event.data instanceof Blob) { - GodotRuntime.error("Blob type not supported"); + GodotRuntime.error('Blob type not supported'); return; - } else if (typeof event.data === "string") { + } else if (typeof event.data === 'string') { is_string = 1; - var enc = new TextEncoder("utf-8"); + const enc = new TextEncoder('utf-8'); buffer = new Uint8Array(enc.encode(event.data)); } else { - GodotRuntime.error("Unknown message type"); + GodotRuntime.error('Unknown message type'); return; } - var len = buffer.length*buffer.BYTES_PER_ELEMENT; - var out = GodotRuntime.malloc(len); + const len = buffer.length * buffer.BYTES_PER_ELEMENT; + const out = GodotRuntime.malloc(len); HEAPU8.set(buffer, out); p_on_message(out, len, is_string); GodotRuntime.free(out); - } + }; }, - close: function(p_id) { + close: function (p_id) { const ref = IDHandler.get(p_id); if (!ref) { return; @@ -84,39 +84,39 @@ const GodotRTCDataChannel = { ref.close(); }, - get_prop: function(p_id, p_prop, p_def) { + get_prop: function (p_id, p_prop, p_def) { const ref = IDHandler.get(p_id); return (ref && ref[p_prop] !== undefined) ? ref[p_prop] : p_def; }, }, - godot_js_rtc_datachannel_ready_state_get: function(p_id) { + godot_js_rtc_datachannel_ready_state_get: function (p_id) { const ref = IDHandler.get(p_id); if (!ref) { return 3; // CLOSED } - switch(ref.readyState) { - case "connecting": - return 0; - case "open": - return 1; - case "closing": - return 2; - case "closed": - default: - return 3; + switch (ref.readyState) { + case 'connecting': + return 0; + case 'open': + return 1; + case 'closing': + return 2; + case 'closed': + default: + return 3; } }, - godot_js_rtc_datachannel_send: function(p_id, p_buffer, p_length, p_raw) { + godot_js_rtc_datachannel_send: function (p_id, p_buffer, p_length, p_raw) { const ref = IDHandler.get(p_id); if (!ref) { return 1; } const bytes_array = new Uint8Array(p_length); - for (var i = 0; i < p_length; i++) { + for (let i = 0; i < p_length; i++) { bytes_array[i] = GodotRuntime.getHeapValue(p_buffer + i, 'i8'); } @@ -129,15 +129,15 @@ const GodotRTCDataChannel = { return 0; }, - godot_js_rtc_datachannel_is_ordered: function(p_id) { + godot_js_rtc_datachannel_is_ordered: function (p_id) { return IDHandler.get_prop(p_id, 'ordered', true); }, - godot_js_rtc_datachannel_id_get: function(p_id) { + godot_js_rtc_datachannel_id_get: function (p_id) { return IDHandler.get_prop(p_id, 'id', 65535); }, - godot_js_rtc_datachannel_max_packet_lifetime_get: function(p_id) { + godot_js_rtc_datachannel_max_packet_lifetime_get: function (p_id) { const ref = IDHandler.get(p_id); if (!ref) { return 65535; @@ -151,15 +151,15 @@ const GodotRTCDataChannel = { return 65535; }, - godot_js_rtc_datachannel_max_retransmits_get: function(p_id) { + godot_js_rtc_datachannel_max_retransmits_get: function (p_id) { return IDHandler.get_prop(p_id, 'maxRetransmits', 65535); }, - godot_js_rtc_datachannel_is_negotiated: function(p_id, p_def) { + godot_js_rtc_datachannel_is_negotiated: function (p_id, p_def) { return IDHandler.get_prop(p_id, 'negotiated', 65535); }, - godot_js_rtc_datachannel_label_get: function(p_id) { + godot_js_rtc_datachannel_label_get: function (p_id) { const ref = IDHandler.get(p_id); if (!ref || !ref.label) { return 0; @@ -167,7 +167,7 @@ const GodotRTCDataChannel = { return GodotRuntime.allocString(ref.label); }, - godot_js_rtc_datachannel_protocol_get: function(p_id) { + godot_js_rtc_datachannel_protocol_get: function (p_id) { const ref = IDHandler.get(p_id); if (!ref || !ref.protocol) { return 0; @@ -175,12 +175,12 @@ const GodotRTCDataChannel = { return GodotRuntime.allocString(ref.protocol); }, - godot_js_rtc_datachannel_destroy: function(p_id) { + godot_js_rtc_datachannel_destroy: function (p_id) { GodotRTCDataChannel.close(p_id); IDHandler.remove(p_id); }, - godot_js_rtc_datachannel_connect: function(p_id, p_ref, p_on_open, p_on_message, p_on_error, p_on_close) { + godot_js_rtc_datachannel_connect: function (p_id, p_ref, p_on_open, p_on_message, p_on_error, p_on_close) { const onopen = GodotRuntime.get_func(p_on_open).bind(null, p_ref); const onmessage = GodotRuntime.get_func(p_on_message).bind(null, p_ref); const onerror = GodotRuntime.get_func(p_on_error).bind(null, p_ref); @@ -188,7 +188,7 @@ const GodotRTCDataChannel = { GodotRTCDataChannel.connect(p_id, onopen, onmessage, onerror, onclose); }, - godot_js_rtc_datachannel_close: function(p_id) { + godot_js_rtc_datachannel_close: function (p_id) { const ref = IDHandler.get(p_id); if (!ref) { return; @@ -203,52 +203,52 @@ mergeInto(LibraryManager.library, GodotRTCDataChannel); const GodotRTCPeerConnection = { $GodotRTCPeerConnection__deps: ['$IDHandler', '$GodotRuntime', '$GodotRTCDataChannel'], $GodotRTCPeerConnection: { - onstatechange: function(p_id, p_conn, callback, event) { + onstatechange: function (p_id, p_conn, callback, event) { const ref = IDHandler.get(p_id); if (!ref) { return; } - var state = 5; // CLOSED - switch(p_conn.iceConnectionState) { - case "new": - state = 0; - break; - case "checking": - state = 1; - break; - case "connected": - case "completed": - state = 2; - break; - case "disconnected": - state = 3; - break; - case "failed": - state = 4; - break; - case "closed": - default: - state = 5; - break; + let state = 5; // CLOSED + switch (p_conn.iceConnectionState) { + case 'new': + state = 0; + break; + case 'checking': + state = 1; + break; + case 'connected': + case 'completed': + state = 2; + break; + case 'disconnected': + state = 3; + break; + case 'failed': + state = 4; + break; + case 'closed': + default: + state = 5; + break; } callback(state); }, - onicecandidate: function(p_id, callback, event) { + onicecandidate: function (p_id, callback, event) { const ref = IDHandler.get(p_id); if (!ref || !event.candidate) { return; } - let c = event.candidate; - let candidate_str = GodotRuntime.allocString(c.candidate); - let mid_str = GodotRuntime.allocString(c.sdpMid); + const c = event.candidate; + const candidate_str = GodotRuntime.allocString(c.candidate); + const mid_str = GodotRuntime.allocString(c.sdpMid); callback(mid_str, c.sdpMLineIndex, candidate_str); GodotRuntime.free(candidate_str); GodotRuntime.free(mid_str); }, - ondatachannel: function(p_id, callback, event) { + ondatachannel: function (p_id, callback, event) { const ref = IDHandler.get(p_id); if (!ref) { return; @@ -258,19 +258,19 @@ const GodotRTCPeerConnection = { callback(cid); }, - onsession: function(p_id, callback, session) { + onsession: function (p_id, callback, session) { const ref = IDHandler.get(p_id); if (!ref) { return; } - let type_str = GodotRuntime.allocString(session.type); - let sdp_str = GodotRuntime.allocString(session.sdp); + const type_str = GodotRuntime.allocString(session.type); + const sdp_str = GodotRuntime.allocString(session.sdp); callback(type_str, sdp_str); GodotRuntime.free(type_str); GodotRuntime.free(sdp_str); }, - onerror: function(p_id, callback, error) { + onerror: function (p_id, callback, error) { const ref = IDHandler.get(p_id); if (!ref) { return; @@ -280,13 +280,13 @@ const GodotRTCPeerConnection = { }, }, - godot_js_rtc_pc_create: function(p_config, p_ref, p_on_state_change, p_on_candidate, p_on_datachannel) { + godot_js_rtc_pc_create: function (p_config, p_ref, p_on_state_change, p_on_candidate, p_on_datachannel) { const onstatechange = GodotRuntime.get_func(p_on_state_change).bind(null, p_ref); const oncandidate = GodotRuntime.get_func(p_on_candidate).bind(null, p_ref); const ondatachannel = GodotRuntime.get_func(p_on_datachannel).bind(null, p_ref); - var config = JSON.parse(GodotRuntime.parseString(p_config)); - var conn = null; + const config = JSON.parse(GodotRuntime.parseString(p_config)); + let conn = null; try { conn = new RTCPeerConnection(config); } catch (e) { @@ -302,7 +302,7 @@ const GodotRTCPeerConnection = { return id; }, - godot_js_rtc_pc_close: function(p_id) { + godot_js_rtc_pc_close: function (p_id) { const ref = IDHandler.get(p_id); if (!ref) { return; @@ -310,7 +310,7 @@ const GodotRTCPeerConnection = { ref.close(); }, - godot_js_rtc_pc_destroy: function(p_id) { + godot_js_rtc_pc_destroy: function (p_id) { const ref = IDHandler.get(p_id); if (!ref) { return; @@ -321,21 +321,21 @@ const GodotRTCPeerConnection = { IDHandler.remove(p_id); }, - godot_js_rtc_pc_offer_create: function(p_id, p_obj, p_on_session, p_on_error) { + godot_js_rtc_pc_offer_create: function (p_id, p_obj, p_on_session, p_on_error) { const ref = IDHandler.get(p_id); if (!ref) { return; } const onsession = GodotRuntime.get_func(p_on_session).bind(null, p_obj); const onerror = GodotRuntime.get_func(p_on_error).bind(null, p_obj); - ref.createOffer().then(function(session) { + ref.createOffer().then(function (session) { GodotRTCPeerConnection.onsession(p_id, onsession, session); - }).catch(function(error) { + }).catch(function (error) { GodotRTCPeerConnection.onerror(p_id, onerror, error); }); }, - godot_js_rtc_pc_local_description_set: function(p_id, p_type, p_sdp, p_obj, p_on_error) { + godot_js_rtc_pc_local_description_set: function (p_id, p_type, p_sdp, p_obj, p_on_error) { const ref = IDHandler.get(p_id); if (!ref) { return; @@ -345,13 +345,13 @@ const GodotRTCPeerConnection = { const onerror = GodotRuntime.get_func(p_on_error).bind(null, p_obj); ref.setLocalDescription({ 'sdp': sdp, - 'type': type - }).catch(function(error) { + 'type': type, + }).catch(function (error) { GodotRTCPeerConnection.onerror(p_id, onerror, error); }); }, - godot_js_rtc_pc_remote_description_set: function(p_id, p_type, p_sdp, p_obj, p_session_created, p_on_error) { + godot_js_rtc_pc_remote_description_set: function (p_id, p_type, p_sdp, p_obj, p_session_created, p_on_error) { const ref = IDHandler.get(p_id); if (!ref) { return; @@ -362,35 +362,35 @@ const GodotRTCPeerConnection = { const onsession = GodotRuntime.get_func(p_session_created).bind(null, p_obj); ref.setRemoteDescription({ 'sdp': sdp, - 'type': type - }).then(function() { + 'type': type, + }).then(function () { if (type !== 'offer') { return Promise.resolve(); } - return ref.createAnswer().then(function(session) { + return ref.createAnswer().then(function (session) { GodotRTCPeerConnection.onsession(p_id, onsession, session); }); - }).catch(function(error) { + }).catch(function (error) { GodotRTCPeerConnection.onerror(p_id, onerror, error); }); }, - godot_js_rtc_pc_ice_candidate_add: function(p_id, p_mid_name, p_mline_idx, p_sdp) { + godot_js_rtc_pc_ice_candidate_add: function (p_id, p_mid_name, p_mline_idx, p_sdp) { const ref = IDHandler.get(p_id); if (!ref) { return; } - var sdpMidName = GodotRuntime.parseString(p_mid_name); - var sdpName = GodotRuntime.parseString(p_sdp); + const sdpMidName = GodotRuntime.parseString(p_mid_name); + const sdpName = GodotRuntime.parseString(p_sdp); ref.addIceCandidate(new RTCIceCandidate({ - "candidate": sdpName, - "sdpMid": sdpMidName, - "sdpMlineIndex": p_mline_idx, + 'candidate': sdpName, + 'sdpMid': sdpMidName, + 'sdpMlineIndex': p_mline_idx, })); }, godot_js_rtc_pc_datachannel_create__deps: ['$GodotRTCDataChannel'], - godot_js_rtc_pc_datachannel_create: function(p_id, p_label, p_config) { + godot_js_rtc_pc_datachannel_create: function (p_id, p_label, p_config) { try { const ref = IDHandler.get(p_id); if (!ref) { @@ -409,5 +409,5 @@ const GodotRTCPeerConnection = { }, }; -autoAddDeps(GodotRTCPeerConnection, '$GodotRTCPeerConnection') +autoAddDeps(GodotRTCPeerConnection, '$GodotRTCPeerConnection'); mergeInto(LibraryManager.library, GodotRTCPeerConnection); diff --git a/modules/websocket/library_godot_websocket.js b/modules/websocket/library_godot_websocket.js index 0856cb13e6..6ada4e7335 100644 --- a/modules/websocket/library_godot_websocket.js +++ b/modules/websocket/library_godot_websocket.js @@ -33,46 +33,46 @@ const GodotWebSocket = { $GodotWebSocket__deps: ['$IDHandler', '$GodotRuntime'], $GodotWebSocket: { // Connection opened, report selected protocol - _onopen: function(p_id, callback, event) { + _onopen: function (p_id, callback, event) { const ref = IDHandler.get(p_id); if (!ref) { return; // Godot object is gone. } - let c_str = GodotRuntime.allocString(ref.protocol); + const c_str = GodotRuntime.allocString(ref.protocol); callback(c_str); GodotRuntime.free(c_str); }, // Message received, report content and type (UTF8 vs binary) - _onmessage: function(p_id, callback, event) { + _onmessage: function (p_id, callback, event) { const ref = IDHandler.get(p_id); if (!ref) { return; // Godot object is gone. } - var buffer; - var is_string = 0; + let buffer; + let is_string = 0; if (event.data instanceof ArrayBuffer) { buffer = new Uint8Array(event.data); } else if (event.data instanceof Blob) { - GodotRuntime.error("Blob type not supported"); + GodotRuntime.error('Blob type not supported'); return; - } else if (typeof event.data === "string") { + } else if (typeof event.data === 'string') { is_string = 1; - var enc = new TextEncoder("utf-8"); + const enc = new TextEncoder('utf-8'); buffer = new Uint8Array(enc.encode(event.data)); } else { - GodotRuntime.error("Unknown message type"); + GodotRuntime.error('Unknown message type'); return; } - var len = buffer.length*buffer.BYTES_PER_ELEMENT; - var out = GodotRuntime.malloc(len); + const len = buffer.length * buffer.BYTES_PER_ELEMENT; + const out = GodotRuntime.malloc(len); HEAPU8.set(buffer, out); callback(out, len, is_string); GodotRuntime.free(out); }, // An error happened, 'onclose' will be called after this. - _onerror: function(p_id, callback, event) { + _onerror: function (p_id, callback, event) { const ref = IDHandler.get(p_id); if (!ref) { return; // Godot object is gone. @@ -81,18 +81,18 @@ const GodotWebSocket = { }, // Connection is closed, this is always fired. Report close code, reason, and clean status. - _onclose: function(p_id, callback, event) { + _onclose: function (p_id, callback, event) { const ref = IDHandler.get(p_id); if (!ref) { return; // Godot object is gone. } - let c_str = GodotRuntime.allocString(event.reason); + const c_str = GodotRuntime.allocString(event.reason); callback(event.code, c_str, event.wasClean ? 1 : 0); GodotRuntime.free(c_str); }, // Send a message - send: function(p_id, p_data) { + send: function (p_id, p_data) { const ref = IDHandler.get(p_id); if (!ref || ref.readyState !== ref.OPEN) { return 1; // Godot object is gone or socket is not in a ready state. @@ -101,7 +101,7 @@ const GodotWebSocket = { return 0; }, - create: function(socket, p_on_open, p_on_message, p_on_error, p_on_close) { + create: function (socket, p_on_open, p_on_message, p_on_error, p_on_close) { const id = IDHandler.add(socket); socket.onopen = GodotWebSocket._onopen.bind(null, id, p_on_open); socket.onmessage = GodotWebSocket._onmessage.bind(null, id, p_on_message); @@ -111,7 +111,7 @@ const GodotWebSocket = { }, // Closes the JavaScript WebSocket (if not already closing) associated to a given C++ object. - close: function(p_id, p_code, p_reason) { + close: function (p_id, p_code, p_reason) { const ref = IDHandler.get(p_id); if (ref && ref.readyState < ref.CLOSING) { const code = p_code; @@ -121,7 +121,7 @@ const GodotWebSocket = { }, // Deletes the reference to a C++ object (closing any connected socket if necessary). - destroy: function(p_id) { + destroy: function (p_id) { const ref = IDHandler.get(p_id); if (!ref) { return; @@ -135,50 +135,50 @@ const GodotWebSocket = { }, }, - godot_js_websocket_create: function(p_ref, p_url, p_proto, p_on_open, p_on_message, p_on_error, p_on_close) { + godot_js_websocket_create: function (p_ref, p_url, p_proto, p_on_open, p_on_message, p_on_error, p_on_close) { const on_open = GodotRuntime.get_func(p_on_open).bind(null, p_ref); const on_message = GodotRuntime.get_func(p_on_message).bind(null, p_ref); const on_error = GodotRuntime.get_func(p_on_error).bind(null, p_ref); const on_close = GodotRuntime.get_func(p_on_close).bind(null, p_ref); const url = GodotRuntime.parseString(p_url); const protos = GodotRuntime.parseString(p_proto); - var socket = null; + let socket = null; try { if (protos) { - socket = new WebSocket(url, protos.split(",")); + socket = new WebSocket(url, protos.split(',')); } else { socket = new WebSocket(url); } } catch (e) { return 0; } - socket.binaryType = "arraybuffer"; + socket.binaryType = 'arraybuffer'; return GodotWebSocket.create(socket, on_open, on_message, on_error, on_close); }, - godot_js_websocket_send: function(p_id, p_buf, p_buf_len, p_raw) { - var bytes_array = new Uint8Array(p_buf_len); - var i = 0; - for(i = 0; i < p_buf_len; i++) { + godot_js_websocket_send: function (p_id, p_buf, p_buf_len, p_raw) { + const bytes_array = new Uint8Array(p_buf_len); + let i = 0; + for (i = 0; i < p_buf_len; i++) { bytes_array[i] = GodotRuntime.getHeapValue(p_buf + i, 'i8'); } - var out = bytes_array.buffer; + let out = bytes_array.buffer; if (!p_raw) { - out = new TextDecoder("utf-8").decode(bytes_array); + out = new TextDecoder('utf-8').decode(bytes_array); } return GodotWebSocket.send(p_id, out); }, - godot_js_websocket_close: function(p_id, p_code, p_reason) { + godot_js_websocket_close: function (p_id, p_code, p_reason) { const code = p_code; const reason = GodotRuntime.parseString(p_reason); GodotWebSocket.close(p_id, code, reason); }, - godot_js_websocket_destroy: function(p_id) { + godot_js_websocket_destroy: function (p_id) { GodotWebSocket.destroy(p_id); }, }; -autoAddDeps(GodotWebSocket, '$GodotWebSocket') +autoAddDeps(GodotWebSocket, '$GodotWebSocket'); mergeInto(LibraryManager.library, GodotWebSocket); |