瀏覽代碼

chrome bug

master
Roderic Day 4 年之前
父節點
當前提交
233a00645d
共有 2 個檔案被更改,包括 10 行新增9 行删除
  1. +8
    -4
      apps/rpc.js
  2. +2
    -5
      apps/video.js

+ 8
- 4
apps/rpc.js 查看文件

const allRPCs = {} const allRPCs = {}


// ensure no data gets lost when sent through the wire
function K(obj) {
return JSON.parse(JSON.stringify(obj))
}

// https://stackoverflow.com/a/2117523 // https://stackoverflow.com/a/2117523
function uuidv4() { function uuidv4() {
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c => return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
const rpc = new RTCPeerConnection(rpcConfig) const rpc = new RTCPeerConnection(rpcConfig)
rpc.onicecandidate = ({candidate}) => { rpc.onicecandidate = ({candidate}) => {
if(candidate && candidate.candidate) { if(candidate && candidate.candidate) {
const cand = JSON.parse(JSON.stringify(candidate))
wire({kind: 'ice-candidate', value: {...cand, uid}, target})
wire({kind: 'ice-candidate', value: {...K(candidate), uid}, target})
} }
} }
rpc.ontrack = ({streams: [stream]}) => { rpc.ontrack = ({streams: [stream]}) => {
const localOffer = await rpc.createOffer() const localOffer = await rpc.createOffer()
await rpc.setLocalDescription(localOffer) await rpc.setLocalDescription(localOffer)


wire({kind: 'rpc-offer', value: {...localOffer, uid}, target})
wire({kind: 'rpc-offer', value: {...K(localOffer), uid}, target})
}) })


addEventListener('rpc-offer', async ({detail}) => { addEventListener('rpc-offer', async ({detail}) => {
const localAnswer = await rpc.createAnswer() const localAnswer = await rpc.createAnswer()
await rpc.setLocalDescription(localAnswer) await rpc.setLocalDescription(localAnswer)


wire({kind: 'rpc-answer', value: {...localAnswer, uid}, target})
wire({kind: 'rpc-answer', value: {...K(localAnswer), uid}, target})
}) })


addEventListener('rpc-answer', async ({detail}) => { addEventListener('rpc-answer', async ({detail}) => {

+ 2
- 5
apps/video.js 查看文件

} }
const Toggle = { const Toggle = {
view({attrs: {key, label}}) { view({attrs: {key, label}}) {
const onclick = async () => {
const onclick = () => {
VideoShare[key] = !VideoShare[key] VideoShare[key] = !VideoShare[key]
await VideoShare.getStream()
State.others.forEach(target =>
signal({kind: 'rpc-needed', value: {kind: 'video', target}})
)
VideoShare.getStream()
} }
const checked = VideoShare[key] const checked = VideoShare[key]
return m('label.styled', return m('label.styled',

Loading…
取消
儲存