-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
# refactoring project, add cookie auth, add server available check
- Loading branch information
Showing
12 changed files
with
1,103 additions
and
963 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,55 @@ | ||
export let CallErrorCode = { | ||
UserHangup : "user_hangup", | ||
InviteTimeout : "invite_timeout" | ||
//other not included | ||
} | ||
|
||
export let CallEvent = { | ||
Hangup : "hangup", | ||
State : "state", | ||
Error : "error", | ||
Replaced : "replaced", | ||
|
||
// The value of isLocalOnHold() has changed | ||
LocalHoldUnhold : "local_hold_unhold", | ||
// The value of isRemoteOnHold() has changed | ||
RemoteHoldUnhold : "remote_hold_unhold", | ||
// backwards compat alias for LocalHoldUnhold: remove in a major version bump | ||
HoldUnhold : "hold_unhold", | ||
// Feeds have changed | ||
FeedsChanged : "feeds_changed", | ||
|
||
AssertedIdentityChanged : "asserted_identity_changed", | ||
|
||
LengthChanged : "length_changed", | ||
|
||
DataChannel : "datachannel", | ||
|
||
SendVoipEvent : "send_voip_event", | ||
|
||
// When the call instantiates its peer connection | ||
// For apps that want to access the underlying peer connection, eg for debugging | ||
PeerConnectionCreated : "peer_connection_created", | ||
} | ||
|
||
let GroupCallEvent = { | ||
GroupCallStateChanged : "group_call_state_changed", | ||
ActiveSpeakerChanged : "active_speaker_changed", | ||
CallsChanged : "calls_changed", | ||
UserMediaFeedsChanged : "user_media_feeds_changed", | ||
ScreenshareFeedsChanged : "screenshare_feeds_changed", | ||
LocalScreenshareStateChanged : "local_screenshare_state_changed", | ||
LocalMuteStateChanged : "local_mute_state_changed", | ||
ParticipantsChanged : "participants_changed", | ||
Error : "group_call_error", | ||
} | ||
|
||
export let LogLevel = { | ||
TRACE: 0, | ||
DEBUG: 1, | ||
INFO: 2, | ||
WARN: 3, | ||
ERROR: 4, | ||
SILENT: 5, | ||
} | ||
|
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,21 @@ | ||
export class StorageInfo { | ||
constructor() { | ||
this.storageItemName = "matrixDemoStorageInfo" | ||
} | ||
load() { | ||
let obj = ((json)=>json && JSON.parse(json))(localStorage.getItem(this.storageItemName)) | ||
if(obj && obj.deviceId && obj.token) { | ||
this.deviceId = obj.deviceId | ||
this.token = obj.token | ||
return this | ||
} | ||
return null | ||
} | ||
save(deviceId, token) { | ||
this.deviceId = deviceId || this.deviceId | ||
this.token = token || this.token | ||
|
||
if(!this.deviceId || !this.token) return | ||
localStorage.setItem(this.storageItemName, JSON.stringify(this)) | ||
} | ||
} |
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,55 @@ | ||
|
||
export function getCurrentTimeString() { | ||
const now = new Date(); | ||
const hours = now.getHours().toString().padStart(2, '0'); | ||
const minutes = now.getMinutes().toString().padStart(2, '0'); | ||
const seconds = now.getSeconds().toString().padStart(2, '0'); | ||
return `${hours}:${minutes}:${seconds}`; | ||
} | ||
|
||
export let isCameraOrWebcamName = function (text) { | ||
// Regular expression to match 'camera' or 'webcam' at the start of the string or after a space | ||
// and not after an open brace '{' | ||
const regex = /^(camera|webcam)|(?<!\(.*)\b( camera| webcam)\b/gi; | ||
|
||
// Search for the pattern in the text | ||
const matches = text.match(regex); | ||
|
||
// Return the matches | ||
return (matches || []).length > 0; | ||
} | ||
|
||
export let calculateHashSha256 = function (string) { | ||
const utf8 = new TextEncoder().encode(string); | ||
let cr = typeof crypto === "undefined" || !!(crypto) === false ? crypto2 : crypto | ||
return cr.subtle.digest('SHA-256', utf8).then((hashBuffer) => { | ||
const hashArray = Array.from(new Uint8Array(hashBuffer)); | ||
const hashHex = hashArray | ||
.map((bytes) => bytes.toString(16).padStart(2, '0')) | ||
.join(''); | ||
return hashHex; | ||
}); | ||
} | ||
|
||
export async function sleepRandom(min, max) { | ||
return sleep(getRandomInt(min, max)) | ||
} | ||
|
||
export async function sleep(ms) { | ||
return (new Promise(resolve => setTimeout(resolve, ms))); | ||
} | ||
|
||
export function getRandomInt(min, max) { | ||
return Math.floor(Math.random() * (max - min)) + min; | ||
} | ||
|
||
export function isFirstHexHigher(hex1, hex2) { | ||
// Convert hex strings to integers | ||
const num1 = parseInt(hex1, 16); | ||
const num2 = parseInt(hex2, 16); | ||
|
||
// Compare the integers | ||
return num1 > num2; | ||
} | ||
|
||
export let streamInfo = (name, stream) => `${name} stream: id:${stream.id}, audio:${stream.getAudioTracks().length > 0}, video:${stream.getVideoTracks().length > 0}` |
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
Oops, something went wrong.