|
@@ -46,7 +46,7 @@ export class MetaGateway
|
|
|
|
|
|
@SubscribeMessage('heartbeat')
|
|
|
handleHeartBeat(client: any, payload: any) {
|
|
|
- this.logger.log(`heartbeat: ${JSON.stringify(payload)}`);
|
|
|
+ // this.logger.log(`heartbeat: ${JSON.stringify(payload)}`);
|
|
|
// console.log('hb', payload);
|
|
|
this.heartBeatFlag = payload;
|
|
|
const pong = {
|
|
@@ -61,11 +61,15 @@ export class MetaGateway
|
|
|
trace_id: '',
|
|
|
user_id: '',
|
|
|
};
|
|
|
- if (this.gameChanel.isOpen()) {
|
|
|
- const heartPack = new DataView(new ArrayBuffer(4));
|
|
|
- heartPack.setUint32(0, 2009889916);
|
|
|
- this.gameChanel.sendMessageBinary(Buffer.from(heartPack.buffer));
|
|
|
- }
|
|
|
+
|
|
|
+ // if (this.gameChanel.isOpen()) {
|
|
|
+ // // console.log('this.gameChanel.isOpen()', this.gameChanel.isOpen());
|
|
|
+ // // this.sendWertcHeartPack(this.gameChanel);
|
|
|
+ // // const heartPack = new DataView(new ArrayBuffer(4));
|
|
|
+ // // heartPack.setUint32(0, 2009889916);
|
|
|
+ // // this.gameChanel.sendMessageBinary(Buffer.from(heartPack.buffer));
|
|
|
+ // // return pong;
|
|
|
+ // }
|
|
|
return pong;
|
|
|
}
|
|
|
|
|
@@ -74,7 +78,10 @@ export class MetaGateway
|
|
|
console.log('handleInitWebRtc');
|
|
|
|
|
|
this.peer = new PeerConnection('roomTest', {
|
|
|
- iceServers: ['stun:120.24.252.95:3478'],
|
|
|
+ // iceServers: ['172.18.156.41:3478'],
|
|
|
+ portRangeBegin: 52000,
|
|
|
+ portRangeEnd: 53000,
|
|
|
+ iceServers: ['stun:120.24.252.95:3478', 'stun:172.18.156.41:3478'],
|
|
|
});
|
|
|
|
|
|
this.peer.onLocalDescription((sdp, type) => {
|
|
@@ -90,7 +97,7 @@ export class MetaGateway
|
|
|
});
|
|
|
|
|
|
this.peer.onLocalCandidate((candidate, mid) => {
|
|
|
- console.warn('peer Candidate:', candidate);
|
|
|
+ console.warn('onLocalCandidate Candidate:', candidate);
|
|
|
const iceRes = {
|
|
|
candidate,
|
|
|
sdpMid: mid,
|
|
@@ -110,8 +117,9 @@ export class MetaGateway
|
|
|
user_id: '',
|
|
|
};
|
|
|
|
|
|
- // client.send(JSON.stringify(res));
|
|
|
+ client.send(JSON.stringify(res));
|
|
|
});
|
|
|
+
|
|
|
this.peer.onStateChange((state) => {
|
|
|
console.log('peer-State:', state);
|
|
|
});
|
|
@@ -126,13 +134,14 @@ export class MetaGateway
|
|
|
|
|
|
this.gameChanel.onOpen(() => {
|
|
|
console.log('channel is open');
|
|
|
+ const peers = this.peer.getSelectedCandidatePair();
|
|
|
+ console.log('peers', peers);
|
|
|
clearInterval(this.timer);
|
|
|
let i = 1;
|
|
|
const paths = path.join(__dirname, '../ws/video/v11');
|
|
|
console.error('__dirname', __dirname);
|
|
|
console.error('paths', paths);
|
|
|
if (this.gameChanel.isOpen()) {
|
|
|
- console.log('gameChanel', this.gameChanel.isOpen());
|
|
|
this.sendWertcHeartPack(this.gameChanel);
|
|
|
}
|
|
|
this.timer = setInterval(() => {
|
|
@@ -161,7 +170,7 @@ export class MetaGateway
|
|
|
console.log('gameChanel onMessage', event);
|
|
|
});
|
|
|
this.gameChanel.onError(() => {
|
|
|
- console.log('gameChanel close');
|
|
|
+ console.log('gameChanel onError');
|
|
|
this.stopSendWertcHeartPack();
|
|
|
});
|
|
|
}
|
|
@@ -171,6 +180,7 @@ export class MetaGateway
|
|
|
heartPack.setUint32(0, 2009889916);
|
|
|
this._webrtcInterval = setInterval(() => {
|
|
|
if (channel.isOpen()) {
|
|
|
+ // console.log('gameChanel', channel);
|
|
|
channel.sendMessageBinary(Buffer.from(heartPack.buffer));
|
|
|
}
|
|
|
}, 1e3);
|
|
@@ -221,7 +231,6 @@ export class MetaGateway
|
|
|
user_id: '',
|
|
|
};
|
|
|
const tt = JSON.stringify(connected);
|
|
|
- // console.log('tt', tt);
|
|
|
|
|
|
client.send(tt);
|
|
|
}
|