diff --git a/xmcl-keystone-ui/src/composables/peers.ts b/xmcl-keystone-ui/src/composables/peers.ts index 18dc1fddb..97c47b578 100644 --- a/xmcl-keystone-ui/src/composables/peers.ts +++ b/xmcl-keystone-ui/src/composables/peers.ts @@ -15,7 +15,7 @@ export function usePeerState(gameProfile: Ref) { const groupState = ref<'connecting' | 'connected' | 'closing' | 'closed'>('closed') const error = ref(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) @@ -27,6 +27,16 @@ export function usePeerState(gameProfile: Ref) { 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) => { @@ -87,7 +97,6 @@ export function usePeerState(gameProfile: Ref) { } return { - id: _id, joinGroup, leaveGroup, setRemoteDescription: _setRemoteDescription,