@leonuh --> see the command below
diff react-janus/src/actions/videoRoom.js react-janus-npm/node_modules/react-janus/lib/actions/videoRoom.js
1c1
< import Janus from '../utils/janus'
'use strict';
3,24c3,56
< export const ATTACH_MCU_ERROR = 'ATTACH_MCU_ERROR'
< export const ROOM_EXISTS_ERROR = 'ROOM_EXISTS_ERROR'
< export const CREATE_ROOM_ERROR = 'CREATE_ROOM_ERROR'
< export const AUDIO_DISABLED = 'AUDIO_DISABLED'
< export const ROOM_LOCAL_FEED = 'ROOM_LOCAL_FEED'
< export const ROOM_LOCAL_FEED_ERROR = 'ROOM_LOCAL_FEED_ERROR'
< export const ROOM_LOCAL_STREAM = 'ROOM_LOCAL_STREAM'
< export const ROOM_REMOTE_FEED = 'ROOM_REMOTE_FEED'
< export const ROOM_REMOTE_FEED_ERROR = 'ROOM_REMOTE_FEED_ERROR'
< export const ROOM_REMOTE_STREAM = 'ROOM_REMOTE_STREAM'
< export const ROOM_REMOVE_FEED = 'ROOM_REMOVE_FEED'
< export const ROOM_DESTROYED = 'ROOM_DESTROYED'
< export const ROOM_ICE_ERROR = 'ROOM_ICE_ERROR'
< export const ROOM_LOCAL_DATA = 'ROOM_LOCAL_DATA'
< export const ROOM_LOCAL_DATA_ERROR = 'ROOM_LOCAL_DATA_ERROR'
< export const ROOM_REMOTE_DATA = 'ROOM_REMOTE_DATA'
< export const ROOM_DATA_OPEN = 'ROOM_DATA_OPEN'
<
< let feeds = []
< let dataSupport = false
< let mypvtid = null
< let opaqueId = 'videoroom-' + Janus.randomString(12)
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.setDataSupport = setDataSupport;
exports.reset = reset;
exports.publishLocalFeed = publishLocalFeed;
exports.sendData = sendData;
exports.attachLocalFeed = attachLocalFeed;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var _utilsJanus = require('../utils/janus');
var _utilsJanus2 = _interopRequireDefault(_utilsJanus);
var ATTACH_MCU_ERROR = 'ATTACH_MCU_ERROR';
exports.ATTACH_MCU_ERROR = ATTACH_MCU_ERROR;
var ROOM_EXISTS_ERROR = 'ROOM_EXISTS_ERROR';
exports.ROOM_EXISTS_ERROR = ROOM_EXISTS_ERROR;
var CREATE_ROOM_ERROR = 'CREATE_ROOM_ERROR';
exports.CREATE_ROOM_ERROR = CREATE_ROOM_ERROR;
var AUDIO_DISABLED = 'AUDIO_DISABLED';
exports.AUDIO_DISABLED = AUDIO_DISABLED;
var ROOM_LOCAL_FEED = 'ROOM_LOCAL_FEED';
exports.ROOM_LOCAL_FEED = ROOM_LOCAL_FEED;
var ROOM_LOCAL_FEED_ERROR = 'ROOM_LOCAL_FEED_ERROR';
exports.ROOM_LOCAL_FEED_ERROR = ROOM_LOCAL_FEED_ERROR;
var ROOM_LOCAL_STREAM = 'ROOM_LOCAL_STREAM';
exports.ROOM_LOCAL_STREAM = ROOM_LOCAL_STREAM;
var ROOM_REMOTE_FEED = 'ROOM_REMOTE_FEED';
exports.ROOM_REMOTE_FEED = ROOM_REMOTE_FEED;
var ROOM_REMOTE_FEED_ERROR = 'ROOM_REMOTE_FEED_ERROR';
exports.ROOM_REMOTE_FEED_ERROR = ROOM_REMOTE_FEED_ERROR;
var ROOM_REMOTE_STREAM = 'ROOM_REMOTE_STREAM';
exports.ROOM_REMOTE_STREAM = ROOM_REMOTE_STREAM;
var ROOM_REMOVE_FEED = 'ROOM_REMOVE_FEED';
exports.ROOM_REMOVE_FEED = ROOM_REMOVE_FEED;
var ROOM_DESTROYED = 'ROOM_DESTROYED';
exports.ROOM_DESTROYED = ROOM_DESTROYED;
var ROOM_ICE_ERROR = 'ROOM_ICE_ERROR';
exports.ROOM_ICE_ERROR = ROOM_ICE_ERROR;
var ROOM_LOCAL_DATA = 'ROOM_LOCAL_DATA';
exports.ROOM_LOCAL_DATA = ROOM_LOCAL_DATA;
var ROOM_LOCAL_DATA_ERROR = 'ROOM_LOCAL_DATA_ERROR';
exports.ROOM_LOCAL_DATA_ERROR = ROOM_LOCAL_DATA_ERROR;
var ROOM_REMOTE_DATA = 'ROOM_REMOTE_DATA';
exports.ROOM_REMOTE_DATA = ROOM_REMOTE_DATA;
var ROOM_DATA_OPEN = 'ROOM_DATA_OPEN';
exports.ROOM_DATA_OPEN = ROOM_DATA_OPEN;
var feeds = [];
var dataSupport = false;
var mypvtid = null;
var opaqueId = 'videoroom-' + _utilsJanus2['default'].randomString(12);
26,27c58,59
< export function setDataSupport(_dataSupport) {
< dataSupport = !!_dataSupport
function setDataSupport(_dataSupport) {
dataSupport = !!_dataSupport;
30,31c62,63
< export function reset() {
< feeds = []
function reset() {
feeds = [];
35,36c67,69
< const { room } = getState().janusConfig
< return new Promise((resolve, reject) => {
var room = getState().janusConfig.room;
return new Promise(function (resolve, reject) {
42c75
< success: (result) => {
success: function success(result) {
44,45c77,78
< if(result.exists && result.exists !== 'false') {
< resolve()
if (result.exists && result.exists !== 'false') {
resolve();
47c80
< reject()
50c83
< error: (error) => {
error: function error(_error) {
53,54c86,87
< message: error
< })
56,57c89,90
< })
< })
});
61,62c94,98
< const { room, publishers } = getState().janusConfig
< return new Promise((resolve, reject) => {
var _getState$janusConfig = getState().janusConfig;
var room = _getState$janusConfig.room;
var publishers = _getState$janusConfig.publishers;
return new Promise(function (resolve, reject) {
65c101
< publishers
67,68c103,104
< success: () => {
< resolve();
success: function success() {
resolve();
70c106
< error: (error) => {
error: function error(_error2) {
73,74c109,110
< message: error
< })
76,77c112,113
< })
< })
});
81,84c117,124
< export function publishLocalFeed(audio, video) {
< return (dispatch, getState) => {
< const {feeds} = getState().videoRoom
< const videoRoomLocal = feeds.filter(feed => !feed.remote)[0].plugin
function publishLocalFeed(audio, video) {
return function (dispatch, getState) {
var feeds = getState().videoRoom.feeds;
var videoRoomLocal = feeds.filter(function (feed) {
return !feed.remote;
})[0].plugin;
87c127
< return new Promise((resolve, reject) => {
return new Promise(function (resolve, reject) {
89c129
< media: {audioRecv: false, videoRecv: false, audioSend: !!audio, videoSend: !!video, audio, video, data: dataSupport}, // Publishers are sendonly
media: { audioRecv: false, videoRecv: false, audioSend: !!audio, videoSend: !!video, audio: audio, video: video, data: dataSupport }, // Publishers are sendonly
91,92c131,132
< success: (jsep) => {
< const publish = {request: 'configure', audio: !!audio, video: !!video}
success: function success(jsep) {
var publish = { request: 'configure', audio: !!audio, video: !!video };
96,97c136,137
< success: () => {
< resolve()
success: function success() {
resolve();
99,100c139,140
< error: (error) => {
< reject(error)
error: function error(_error3) {
reject(_error3);
102c142
< })
106c146
< })
109c149
< error: (message) => {
error: function error(message) {
114c154
< reject(message)
117,118c157,158
< message
< })
121,123c161,163
< })
< })
< }
};
126c166
< export function sendData(data) {
function sendData(data) {
129,131c169,174
< return (dispatch, getState) => {
< const {feeds} = getState().videoRoom
< const videoRoomLocal = feeds.filter(feed => !feed.remote)[0].plugin
return function (dispatch, getState) {
var feeds = getState().videoRoom.feeds;
var videoRoomLocal = feeds.filter(function (feed) {
return !feed.remote;
})[0].plugin;
133c176
< return new Promise((resolve, reject) => {
return new Promise(function (resolve, reject) {
136,137c179,180
< success: () => {
< resolve()
success: function success() {
resolve();
140,141c183,184
< data
< })
143,144c186,187
< error: (message) => {
< reject(message)
error: function error(message) {
reject(message);
147,148c190,191
< message
< })
150,152c193,195
< })
< })
< }
};
156,164c199,208
< return (dispatch, getState) => {
< const { room, user } = getState().janusConfig
< const joinToRoom = () => {
< const data = { request: 'join', room: room.room, ptype: 'publisher', display: JSON.stringify(user) }
< videoRoomLocal.send({message: data})
< }
< isRoomExists(dispatch, getState, videoRoomLocal)
< .then(joinToRoom)
< .catch(() => {
return function (dispatch, getState) {
var _getState$janusConfig2 = getState().janusConfig;
var room = _getState$janusConfig2.room;
var user = _getState$janusConfig2.user;
var joinToRoom = function joinToRoom() {
var data = { request: 'join', room: room.room, ptype: 'publisher', display: JSON.stringify(user) };
videoRoomLocal.send({ message: data });
};
isRoomExists(dispatch, getState, videoRoomLocal).then(joinToRoom)['catch'](function () {
166,168c210,211
< if(room.request && room.request === 'create') {
< createRoom(dispatch, getState, videoRoomLocal)
< .then(joinToRoom)
if (room.request && room.request === 'create') {
createRoom(dispatch, getState, videoRoomLocal).then(joinToRoom);
170,171c213,214
< })
< }
};
176,181c219,227
< return (dispatch, getState) => {
< const { room, publishers } = getState().janusConfig
< const { janus } = getState().mcu
< let feed = {
< id,
< user,
return function (dispatch, getState) {
var _getState$janusConfig3 = getState().janusConfig;
var room = _getState$janusConfig3.room;
var publishers = _getState$janusConfig3.publishers;
var janus = getState().mcu.janus;
var feed = {
id: id,
user: user,
183c229
< }
187,188c233,234
< success: (pluginHandle) => {
< feed.plugin = pluginHandle
success: function success(pluginHandle) {
feed.plugin = pluginHandle;
190,191c236,237
< const listen = { request: 'join', room: room.room, ptype: 'listener', feed: feed.id, private_id: mypvtid }
< feed.plugin.send({message: listen})
var listen = { request: 'join', room: room.room, ptype: 'listener', feed: feed.id, private_id: mypvtid };
feed.plugin.send({ message: listen });
193c239
< error: (error) => {
error: function error(_error4) {
196,197c242,243
< message: error
< })
199,202c245,248
< onmessage: (msg, jsep) => {
< var event = msg.videoroom
< if(event) {
< if(event === 'attached') {
onmessage: function onmessage(msg, jsep) {
var event = msg.videoroom;
if (event) {
if (event === 'attached') {
205,207c251,255
< const existedFeed = feeds.filter(_feed => feed.user.id === _feed.user.id)[0]
< if(!existedFeed) {
< feeds.push(feed)
var existedFeed = feeds.filter(function (_feed) {
return feed.user.id === _feed.user.id;
})[0];
if (!existedFeed) {
feeds.push(feed);
210c258
< feed,
212c260
< })
216,217c264,265
< // What has just happened?
< }
// What has just happened?
}
219c267
< if(jsep) {
225,227c273,275
< success: (jsep) => {
< const body = { request: 'start', room: room.room }
< feed.plugin.send({message: body, jsep: jsep})
success: function success(jsep) {
var body = { request: 'start', room: room.room };
feed.plugin.send({ message: body, jsep: jsep });
229c277
< error: (error) => {
error: function error(_error5) {
233,234c281,282
< message: error
< })
236c284
< })
239,240c287,288
< webrtcState: (on) => {
< Janus.log("Janus says this WebRTC PeerConnection (feed #" + feed.user.id + ") is " + (on ? "up" : "down") + " now")
webrtcState: function webrtcState(on) {
_utilsJanus2['default'].log("Janus says this WebRTC PeerConnection (feed #" + feed.user.id + ") is " + (on ? "up" : "down") + " now");
242c290
< ondata: (data) => {
ondata: function ondata(data) {
246c294
< })
248c296
< onlocalstream: (stream) => {
onlocalstream: function onlocalstream(stream) {
251c299
< onremotestream: (stream) => {
onremotestream: function onremotestream(stream) {
253,254c301,302
< feeds.forEach((_feed, i) => {
< if(_feed.id === feed.id) {
feeds.forEach(function (_feed, i) {
if (_feed.id === feed.id) {
256,257c304,305
< stream
< })
261c309
< feed,
263c311
< })
265c313
< })
267,268c315
< oncleanup: () => {
< }
oncleanup: function oncleanup() {}
270c317
< }
};
273,280c320,330
< export function attachLocalFeed(janus) {
< return (dispatch, getState) => {
< const { publishers, user } = getState().janusConfig
< const { janus } = getState().mcu
< const addRemoteFeed = (publishers) => {
< let list = publishers
< for(let f in list) {
< dispatch(attachRemoteFeed(list[f].id, JSON.parse(list[f].display)))
function attachLocalFeed(janus) {
return function (dispatch, getState) {
var _getState$janusConfig4 = getState().janusConfig;
var publishers = _getState$janusConfig4.publishers;
var user = _getState$janusConfig4.user;
var janus = getState().mcu.janus;
var addRemoteFeed = function addRemoteFeed(publishers) {
var list = publishers;
for (var f in list) {
dispatch(attachRemoteFeed(list[f].id, JSON.parse(list[f].display)));
282,284c332,334
< }
< let feed = {
< user,
};
var feed = {
user: user,
286c336
< }
292,294c342,344
< success: (pluginHandle) => {
< feed.plugin = pluginHandle
< dispatch(join(feed.plugin))
success: function success(pluginHandle) {
feed.plugin = pluginHandle;
dispatch(join(feed.plugin));
296c346
< error: (error) => {
error: function error(_error6) {
299,300c349,350
< message: error
< })
302,303c352,353
< consentDialog: (on) => {
< Janus.debug("Consent dialog should be " + (on ? "on" : "off") + " now")
consentDialog: function consentDialog(on) {
_utilsJanus2['default'].debug("Consent dialog should be " + (on ? "on" : "off") + " now");
305,306c355,356
< mediaState: (medium, on) => {
< Janus.log("Janus " + (on ? "started" : "stopped") + " receiving our " + medium)
mediaState: function mediaState(medium, on) {
_utilsJanus2['default'].log("Janus " + (on ? "started" : "stopped") + " receiving our " + medium);
308,309c358,359
< webrtcState: (on) => {
< Janus.log("Janus says our WebRTC PeerConnection is " + (on ? "up" : "down") + " now")
webrtcState: function webrtcState(on) {
_utilsJanus2['default'].log("Janus says our WebRTC PeerConnection is " + (on ? "up" : "down") + " now");
311c361
< ondataopen: () => {
ondataopen: function ondataopen() {
314c364
< })
316,325c366,377
< onmessage: (msg, jsep) => {
< let event = msg.videoroom;
< if(event) {
< if(event === 'joined') {
< const { publishers, id, private_id } = msg
<
< mypvtid = private_id
< feed.id = id
< feeds.push(feed)
<
onmessage: function onmessage(msg, jsep) {
var event = msg.videoroom;
if (event) {
if (event === 'joined') {
var _publishers = msg.publishers;
var id = msg.id;
var private_id = msg.private_id;
mypvtid = private_id;
feed.id = id;
feeds.push(feed);
327,328c379,380
< if(publishers) {
< addRemoteFeed(publishers)
if (_publishers) {
addRemoteFeed(_publishers);
332c384
< feed,
334,335c386,387
< })
< } else if(event === 'destroyed') {
});
} else if (event === 'destroyed') {
339,340c391,392
< })
< } else if(event === 'event') {
});
} else if (event === 'event') {
342,360c394,416
< if(msg.publishers) {
< addRemoteFeed(msg.publishers)
< } else if(msg.leaving) {
< // One of the publishers has gone away?
< let leaving = msg.leaving,
< removeFeed = feeds.filter(feed => feed.id == leaving)
<
< //Remove feed
< if(removeFeed[0]) {
< removeFeed = removeFeed[0]
< removeFeed.plugin.detach()
< feeds.splice(feeds.indexOf(removeFeed), 1)
< dispatch({
< type: ROOM_REMOVE_FEED,
< feed: removeFeed,
< feeds: feeds.slice(0)
< })
< }
< } else if(msg.error) {
if (msg.publishers) {
addRemoteFeed(msg.publishers);
} else if (msg.leaving) {
(function () {
// One of the publishers has gone away?
var leaving = msg.leaving,
removeFeed = feeds.filter(function (feed) {
return feed.id == leaving;
});
//Remove feed
if (removeFeed[0]) {
removeFeed = removeFeed[0];
removeFeed.plugin.detach();
feeds.splice(feeds.indexOf(removeFeed), 1);
dispatch({
type: ROOM_REMOVE_FEED,
feed: removeFeed,
feeds: feeds.slice(0)
});
}
})();
} else if (msg.error) {
365,366c421,422
< if(jsep) {
< feed.plugin.handleRemoteJsep({jsep: jsep})
if (jsep) {
feed.plugin.handleRemoteJsep({ jsep: jsep });
369c425
< onlocalstream: (stream) => {
onlocalstream: function onlocalstream(stream) {
371c427
< const index = feeds.indexOf(feed);
var index = feeds.indexOf(feed);
373,374c429,430
< stream
< })
378c434
< feed,
380c436
< })
382,384c438,441
< const { pc } = feed.plugin.webrtcStuff
< if(pc) {
< pc.oniceconnectionstatechange = () => {
var pc = feed.plugin.webrtcStuff.pc;
if (pc) {
pc.oniceconnectionstatechange = function () {
389c446
< })
391c448
< }
394c451
< onremotestream: (stream) => {
onremotestream: function onremotestream(stream) {
397c454
< oncleanup: () => {
oncleanup: function oncleanup() {
400,402c457,459
< })
< }
< }
};
}
\ No newline at end of file