Comments (3)
我也遇到这个问题,打开了peerjs的debug看到是由于包太大导致的,对于大页面初始包会比较大,可以简单的自己实现一个peerjs的传输在发送时将发送的数据分片,接收的时候重新拼装
这个问题你解决了吗?
解决了,因为我只是做一个demo所以在发送的时候将数据进行了简单的拆分
async send<T>(data: T) {
if (!this.conn) {
await this.connect();
}
while (this.role === 'embed' && !this.opened) {
// a spin lock to wait connection open
await sleep(50);
}
let dataStr = JSON.stringify(data);
const MAX_LENGTH = 200000;
if (dataStr.length > MAX_LENGTH) {
const count = Math.ceil(dataStr.length / MAX_LENGTH);
for (let i = 0; i < count; i++) {
const sendData = dataStr.slice(0, Math.min(dataStr.length, MAX_LENGTH));
dataStr = dataStr.slice(Math.min(dataStr.length, MAX_LENGTH));
this.conn?.send(`part${i + 1}-${count}endpart;${sendData}`);
}
} else {
this.conn?.send(data);
}
}
然后在接收的地方重新组装
conn.on('data', data => {
data = this.joinData(data);
if (!data) return;
const { event, payload } = data;
this.handlers[event as TransporterEvents].map(h =>
h({
event: event,
payload: payload,
})
);
});
joinData (data:any) {
if (typeof data === 'string' && data.startsWith('part') && data.includes('endpart;')) {
const partData = data.split('endpart;');
const index = parseInt(partData[0].split('-')[0].replace('part', ''), 10);
const count = parseInt(partData[0].split('-')[1], 10);
this.temp[index - 1] = partData[1];
this.tempLength = this.tempLength + 1;
console.log(`收到了拆包,当前包${index},共计:${count},已接收:${this.temp.length}`)
if (this.tempLength !== count) return
data = JSON.parse(this.temp.join(''));
this.temp = [];
this.tempLength = 0;
}
return data;
}
from syncit.
我也遇到这个问题,打开了peerjs的debug看到是由于包太大导致的,对于大页面初始包会比较大,可以简单的自己实现一个peerjs的传输在发送时将发送的数据分片,接收的时候重新拼装
from syncit.
我也遇到这个问题,打开了peerjs的debug看到是由于包太大导致的,对于大页面初始包会比较大,可以简单的自己实现一个peerjs的传输在发送时将发送的数据分片,接收的时候重新拼装
这个问题你解决了吗?
from syncit.
Related Issues (20)
- Not working on mobile using PeerjsTransporter HOT 4
- Stream active session to 1:n users HOT 1
- Getting Started // Documentations is required HOT 13
- How do you use English locale? HOT 1
- Can syncit be used with socket? HOT 3
- 如果需要远程整个桌面完全控制,而不仅仅是控制web页面时怎么办? HOT 1
- 大佬你好,请问项目中如何引入静态图片,必须是svg吗? HOT 3
- Not working with Angular application HOT 1
- IOS/Safari Remote control can not scroll HOT 1
- 大佬,这个库不维护了吗? HOT 2
- How to start this project HOT 2
- 大佬 怎么在项目里引入这个库
- ios播放无法滚动
- Unable to run this project HOT 1
- 怎么默认开启远程控制?
- 能否使用WebSocketTransporter? HOT 3
- 【有偿】要怎么更新rrweb依赖的版本?,使之支持canvas回放 HOT 5
- How do I control which events are going from the mirror to the source during remote control?
- 如何运行起来? 备忘 HOT 1
- Error: 'default' is not exported by node_modules/@syncit/ui/dist/index.mjs HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from syncit.