【m】聊天消息接入
This commit is contained in:
@@ -22,7 +22,7 @@ export class RenderStreaming {
|
||||
this.onGotAnswer = function (connectionId) { Logger.log(`On got Answer on ${connectionId}.`); };
|
||||
this.onTrackEvent = function (data) { Logger.log(`OnTrack event peer with data:${data}`); };
|
||||
this.onAddChannel = function (data) { Logger.log(`onAddChannel event peer with data:${data}`); };
|
||||
|
||||
this.onMessage = function (data) { Logger.log(`On message: ${data}`); };
|
||||
this._config = config;
|
||||
this._signaling = signaling;
|
||||
this._signaling.addEventListener('connect', this._onConnect.bind(this));
|
||||
@@ -30,6 +30,7 @@ export class RenderStreaming {
|
||||
this._signaling.addEventListener('offer', this._onOffer.bind(this));
|
||||
this._signaling.addEventListener('answer', this._onAnswer.bind(this));
|
||||
this._signaling.addEventListener('candidate', this._onIceCandidate.bind(this));
|
||||
this._signaling.addEventListener('on-message', this._onMessage.bind(this));
|
||||
}
|
||||
|
||||
async _onConnect(e) {
|
||||
@@ -85,7 +86,11 @@ export class RenderStreaming {
|
||||
await this._peer.onGotCandidate(candidate.connectionId, iceCandidate);
|
||||
}
|
||||
}
|
||||
|
||||
// 在 RenderStreaming 类中添加
|
||||
async _onMessage(e) {
|
||||
const data = e.detail;
|
||||
this.onMessage(data);
|
||||
}
|
||||
/**
|
||||
* if not set argument, a generated uuid is used.
|
||||
* @param {string | null} connectionId
|
||||
@@ -98,6 +103,7 @@ export class RenderStreaming {
|
||||
async deleteConnection() {
|
||||
await this._signaling.deleteConnection(this._connectionId);
|
||||
}
|
||||
// 在 RenderStreaming 类中添加
|
||||
|
||||
_preparePeerConnection(connectionId, polite) {
|
||||
if (this._peer) {
|
||||
@@ -182,6 +188,11 @@ export class RenderStreaming {
|
||||
return this._peer.getTransceivers(this._connectionId);
|
||||
}
|
||||
|
||||
sendMessage(message) {
|
||||
if (this._signaling && this._connectionId) {
|
||||
this._signaling.sendMessage(this._connectionId, message);
|
||||
}
|
||||
}
|
||||
async start() {
|
||||
await this._signaling.start();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user