Skip to content

Commit

Permalink
fix: crypto.randomUUID is missing in prod causing the launcher blocked
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Dec 23, 2023
1 parent f860747 commit b9df5c0
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions xmcl-keystone-ui/src/composables/peers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function usePeerState(gameProfile: Ref<GameProfileAndTexture>) {
const groupState = ref<'connecting' | 'connected' | 'closing' | 'closed'>('closed')
const error = ref<Error | undefined>(undefined)
let _group: PeerGroup | undefined
const _id = crypto.randomUUID()
let _id = ''

on('connection-local-description', ({ description, type }) => {
_group?.sendLocalDescription(description.id, description.sdp, type, description.candidates)
Expand All @@ -27,6 +27,16 @@ export function usePeerState(gameProfile: Ref<GameProfileAndTexture>) {
window.crypto.getRandomValues(buf)
groupId = gameProfile.value.name + '@' + buf[0]
}
if (!_id) {
try {
_id = window.crypto.randomUUID()
} catch {
const buf = new Uint16Array(16)
window.crypto.getRandomValues(buf)
const str = [...buf].map(v => v.toString(16)).join('')
_id = str
}
}
_group = new PeerGroup(groupId, _id)

_group.onheartbeat = (sender) => {
Expand Down Expand Up @@ -87,7 +97,6 @@ export function usePeerState(gameProfile: Ref<GameProfileAndTexture>) {
}

return {
id: _id,
joinGroup,
leaveGroup,
setRemoteDescription: _setRemoteDescription,
Expand Down

0 comments on commit b9df5c0

Please sign in to comment.