Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/sdk/p2p/p2pclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ const P2PClient = function(configuration, signalingChannel) {
const data = JSON.parse(message);
if (data.type === 'chat-closed') {
if (channels.has(origin)) {
getOrCreateChannel(origin).onMessage(data);
getOrCreateChannel(origin, false).onMessage(data);
channels.delete(origin);
}
return;
}
if (self.allowedRemoteIds.indexOf(origin) >= 0) {
getOrCreateChannel(origin).onMessage(data);
getOrCreateChannel(origin, false).onMessage(data);
} else {
sendSignalingMessage(origin, 'chat-closed',
ErrorModule.errors.P2P_CLIENT_DENIED);
Expand Down Expand Up @@ -186,7 +186,7 @@ const P2PClient = function(configuration, signalingChannel) {
return Promise.reject(new ErrorModule.P2PError(
ErrorModule.errors.P2P_CLIENT_NOT_ALLOWED));
}
return Promise.resolve(getOrCreateChannel(remoteId).publish(stream));
return Promise.resolve(getOrCreateChannel(remoteId, true).publish(stream));
};

/**
Expand All @@ -208,7 +208,7 @@ const P2PClient = function(configuration, signalingChannel) {
return Promise.reject(new ErrorModule.P2PError(
ErrorModule.errors.P2P_CLIENT_NOT_ALLOWED));
}
return Promise.resolve(getOrCreateChannel(remoteId).send(message));
return Promise.resolve(getOrCreateChannel(remoteId, true).send(message));
};

/**
Expand Down Expand Up @@ -263,13 +263,13 @@ const P2PClient = function(configuration, signalingChannel) {
});
};

const getOrCreateChannel = function(remoteId) {
const getOrCreateChannel = function(remoteId, isInitializer) {
if (!channels.has(remoteId)) {
// Construct an signaling sender/receiver for P2PPeerConnection.
const signalingForChannel = Object.create(EventDispatcher);
signalingForChannel.sendSignalingMessage = sendSignalingMessage;
const pcc = new P2PPeerConnectionChannel(config, myId, remoteId,
signalingForChannel);
signalingForChannel, isInitializer);
pcc.addEventListener('streamadded', (streamEvent)=>{
self.dispatchEvent(streamEvent);
});
Expand Down
36 changes: 6 additions & 30 deletions src/sdk/p2p/peerconnection-channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const sysInfo = Utils.sysInfo();
class P2PPeerConnectionChannel extends EventDispatcher {
// |signaling| is an object has a method |sendSignalingMessage|.
/* eslint-disable-next-line require-jsdoc */
constructor(config, localId, remoteId, signaling) {
constructor(config, localId, remoteId, signaling, isInitializer) {
super();
this._config = config;
this._localId = localId;
Expand Down Expand Up @@ -93,6 +93,10 @@ class P2PPeerConnectionChannel extends EventDispatcher {
this._infoSent = false;
this._disposed = false;
this._createPeerConnection();
if (isInitializer) {
this._sendSignalingMessage(SignalingType.CLOSED);
}
this._sendSignalingMessage(SignalingType.UA, sysInfo);
}

/**
Expand All @@ -114,9 +118,7 @@ class P2PPeerConnectionChannel extends EventDispatcher {
ErrorModule.errors.P2P_CLIENT_INVALID_STATE,
'All tracks are ended.'));
}
return Promise.all([this._sendClosedMsgIfNecessary(),
this._sendSysInfoIfNecessary(),
this._sendStreamInfo(stream)]).then(() => {
return this._sendStreamInfo(stream).then(() => {
return new Promise((resolve, reject) => {
// Replace |addStream| with PeerConnection.addTrack when all browsers are ready.
for (const track of stream.mediaStream.getTracks()) {
Expand Down Expand Up @@ -159,14 +161,6 @@ class P2PPeerConnectionChannel extends EventDispatcher {
this._createDataChannel(DataChannelLabel.MESSAGE);
}

this._sendClosedMsgIfNecessary().catch((err) => {
Logger.debug('Failed to send closed message.' + err.message);
});

this._sendSysInfoIfNecessary().catch((err) => {
Logger.debug('Failed to send sysInfo.' + err.message);
});

const dc = this._dataChannels.get(DataChannelLabel.MESSAGE);
if (dc.readyState === 'open') {
this._dataChannels.get(DataChannelLabel.MESSAGE).send(
Expand Down Expand Up @@ -242,7 +236,6 @@ class P2PPeerConnectionChannel extends EventDispatcher {
switch (message.type) {
case SignalingType.UA:
this._handleRemoteCapability(message.data);
this._sendSysInfoIfNecessary();
break;
case SignalingType.TRACK_SOURCES:
this._trackSourcesHandler(message.data);
Expand Down Expand Up @@ -803,23 +796,6 @@ class P2PPeerConnectionChannel extends EventDispatcher {
]);
}


_sendSysInfoIfNecessary() {
if (this._infoSent) {
return Promise.resolve();
}
this._infoSent = true;
return this._sendSignalingMessage(SignalingType.UA, sysInfo);
}

_sendClosedMsgIfNecessary() {
if (this._pc.remoteDescription === null ||
this._pc.remoteDescription.sdp === '') {
return this._sendSignalingMessage(SignalingType.CLOSED);
}
return Promise.resolve();
}

_handleRemoteCapability(ua) {
if (ua.sdk && ua.sdk && ua.sdk.type === 'JavaScript' && ua.runtime &&
ua.runtime.name === 'Firefox') {
Expand Down