MCPcopy Create free account
hub / github.com/ShouChenICU/FastSend / initSend

Function initSend

server/api/connect.ts:58–78  ·  view source on GitHub ↗
(peer: any)

Source from the content-addressed store, hash-verified

56
57// 初始化发送端
58function initSend(peer: any) {
59 if (peer.isInited) {
60 return
61 }
62 let code = genDigitCode(4)
63 let retryCount = 2048
64 while (waitConnectPool.has(code)) {
65 if (retryCount-- <= 0) {
66 peer.send(JSON.stringify({ type: 'err', data: -1, msg: 'Init code fail' }))
67 throw new Error('Init code fail')
68 }
69 // 碰撞时重新生成取件码
70 code = genDigitCode(4)
71 }
72 waitConnectPool.set(code, peer)
73 peer.isInited = true
74 initPool.delete(peer.id)
75 // 初始化发送端成功,返回连接码
76 peer.send(JSON.stringify({ type: 'code', code: code }))
77 heartbeat(peer)
78}
79
80// 初始化接收端
81function initReceive(peer: any, code: string) {

Callers 1

messageFunction · 0.85

Calls 2

genDigitCodeFunction · 0.85
heartbeatFunction · 0.85

Tested by

no test coverage detected