-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate from IIFE to modern ES modules
These modules should be supported by all contemporary browsers, and this transition should resolve most issues related to the explicit import order of the .js files.
- Loading branch information
1 parent
2aaf37b
commit 2bc64a3
Showing
36 changed files
with
3,897 additions
and
3,831 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import {log} from 'log'; | ||
|
||
const endpoints = { | ||
LATENCY_CHECK: 3, | ||
INIT: 4, | ||
INIT_WEBRTC: 100, | ||
OFFER: 101, | ||
ANSWER: 102, | ||
ICE_CANDIDATE: 103, | ||
GAME_START: 104, | ||
GAME_QUIT: 105, | ||
GAME_SAVE: 106, | ||
GAME_LOAD: 107, | ||
GAME_SET_PLAYER_INDEX: 108, | ||
GAME_RECORDING: 110, | ||
GET_WORKER_LIST: 111, | ||
GAME_ERROR_NO_FREE_SLOTS: 112, | ||
|
||
APP_VIDEO_CHANGE: 150, | ||
} | ||
|
||
/** | ||
* Server API. | ||
* | ||
* Requires the actual api.transport implementation. | ||
*/ | ||
export const api = { | ||
set transport(t) { | ||
transport = t; | ||
}, | ||
endpoint: endpoints, | ||
decode: (b) => JSON.parse(decodeBytes(b)), | ||
server: { | ||
initWebrtc: () => packet(endpoints.INIT_WEBRTC), | ||
sendIceCandidate: (candidate) => packet(endpoints.ICE_CANDIDATE, btoa(JSON.stringify(candidate))), | ||
sendSdp: (sdp) => packet(endpoints.ANSWER, btoa(JSON.stringify(sdp))), | ||
latencyCheck: (id, list) => packet(endpoints.LATENCY_CHECK, list, id), | ||
getWorkerList: () => packet(endpoints.GET_WORKER_LIST), | ||
}, | ||
game: { | ||
load: () => packet(endpoints.GAME_LOAD), | ||
save: () => packet(endpoints.GAME_SAVE), | ||
setPlayerIndex: (i) => packet(endpoints.GAME_SET_PLAYER_INDEX, i), | ||
start: (game, roomId, record, recordUser, player) => packet(endpoints.GAME_START, { | ||
game_name: game, | ||
room_id: roomId, | ||
player_index: player, | ||
record: record, | ||
record_user: recordUser, | ||
}), | ||
toggleRecording: (active = false, userName = '') => | ||
packet(endpoints.GAME_RECORDING, {active: active, user: userName}), | ||
quit: (roomId) => packet(endpoints.GAME_QUIT, {room_id: roomId}), | ||
} | ||
} | ||
|
||
let transport = { | ||
send: (packet) => { | ||
log.warn('Default transport is used! Change it with the api.transport variable.', packet) | ||
} | ||
} | ||
|
||
const packet = (type, payload, id) => { | ||
const packet = {t: type}; | ||
if (id !== undefined) packet.id = id; | ||
if (payload !== undefined) packet.p = payload; | ||
transport.send(packet); | ||
} | ||
|
||
const decodeBytes = (b) => String.fromCharCode.apply(null, new Uint8Array(b)) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.