Skip to content
This repository was archived by the owner on Oct 25, 2024. It is now read-only.

Commit a48ffcb

Browse files
jianjunzlzhai
authored andcommitted
Pick some changes to 4.2.x. (#149)
* Fix port, line number reference in p2p sample README Also, fix some formatting and add some helpful text. Signed-off-by: Geoff Gustafson <[email protected]> * moving to getDisplayMedia * apply comments
1 parent 5ddeedf commit a48ffcb

File tree

8 files changed

+68
-198
lines changed

8 files changed

+68
-198
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Open WebRTC Toolkit JavaScript SDK builds on top of the W3C standard WebRTC APIs to accelerate development of real-time communications (RTC) for web applications, including peer-to-peer, broadcasting, and conference mode communications.
44

55
## How to build release package
6-
1. Run `npm install -g grunt-cli` to install grunt.
6+
1. Run `npm install -g grunt-cli` to install grunt. (You may need to `chown -R $USER /usr/local` for this to work.)
77
2. Go to "scripts" folder.
88
3. Run `npm install` to install development dependencies.
99
4. Run `grunt`.

src/extension/screen-sharing-chrome-extension/manifest.json

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/extension/screen-sharing-chrome-extension/script.js

Lines changed: 0 additions & 36 deletions
This file was deleted.
Binary file not shown.
Binary file not shown.
Binary file not shown.

src/samples/p2p/README.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
#How to run p2p sample
2-
###1st step: Run Woogeen p2p server
3-
To run the server, you need to install node and npm, then change directory into server, and install all modules listed as dependencies in package.json by using command **`npm install`** .
4-
After dependencies successfully installed, you can run the peerserver.js by using command **`node peerserver.js`**. It will listen on port 8085/8096.
5-
###2nd step: Deploy p2p sample page and sdk on web server
1+
# How to run p2p sample
2+
3+
## Step 1: Run p2p server
4+
To run the server, you need to install node and npm, then change into the [owt-server-p2p](https://github.com/open-webrtc-toolkit/owt-server-p2p) source directory, and install all modules listed as dependencies in package.json by using command `npm install` .
5+
After the dependencies are successfully installed, you can run the peer server by using the command `node peerserver.js`. It will listen on ports 8095/8096.
6+
7+
## Step 2: Deploy p2p sample page and sdk on web server
68
You need to edit the sample page `peercall.html`:
79

8-
- Set serverAddress in line 128, change `example.com` to your p2p server address.
9-
- Set correct ICE server address.
10+
- Set serverAddress on line 112: change `example.com` to your p2p server address.
11+
- Set correct ICE server addresses below that.
12+
13+
Then choose a webserver such as Apache, and deploy the page and the sdk.
1014

11-
Then choose a webserver such as apache, deploy the page and sdk.
15+
## Step 3: Visit the website
16+
You can then visit the page from a web browser, with a URL such as https://server.domain.com:<PORT>/peercall.html
1217

13-
###3rd step: Visit the website
14-
You can visit the page on web browser
18+
Open the web page from two clients with cameras connected, and choose two names. On one, type the first name and click **Login**, then type the second name and click **Set Remote Id**. On the other client, swap the names. Then click **Share Camera** on each to stream video.

src/sdk/base/mediastream-factory.js

Lines changed: 53 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class VideoTrackConstraints {
5252
// eslint-disable-next-line require-jsdoc
5353
constructor(source) {
5454
if (!Object.values(MediaFormatModule.VideoSourceInfo)
55-
.some((v) => v === source)) {
55+
.some((v) => v === source)) {
5656
throw new TypeError('Invalid source.');
5757
}
5858
/**
@@ -94,7 +94,6 @@ export class VideoTrackConstraints {
9494
* @constructor
9595
* @param {?Owt.Base.AudioTrackConstraints} audioConstraints
9696
* @param {?Owt.Base.VideoTrackConstraints} videoConstraints
97-
* @param {?string} extensionId The ID of Chrome screen sharing extension.
9897
*/
9998
export class StreamConstraints {
10099
// eslint-disable-next-line require-jsdoc
@@ -111,19 +110,13 @@ export class StreamConstraints {
111110
* @instance
112111
*/
113112
this.video = videoConstraints;
114-
/**
115-
* @member {string} extensionId
116-
* @memberof Owt.Base.MediaStreamDeviceConstraints
117-
* @desc The ID of Chrome Extension for screen sharing.
118-
* @instance
119-
*/
120113
}
121114
}
122115

123116
// eslint-disable-next-line require-jsdoc
124117
function isVideoConstrainsForScreenCast(constraints) {
125118
return (typeof constraints.video === 'object' && constraints.video.source ===
126-
MediaFormatModule.VideoSourceInfo.SCREENCAST);
119+
MediaFormatModule.VideoSourceInfo.SCREENCAST);
127120
}
128121

129122
/**
@@ -170,123 +163,63 @@ export class MediaStreamFactory {
170163
'Cannot capture video from screen cast while capture audio from'
171164
+ ' other source.'));
172165
}
173-
// Screen sharing on Chrome does not work with the latest constraints
174-
// format.
175-
if (isVideoConstrainsForScreenCast(constraints) && utils.isChrome()) {
176-
if (!constraints.extensionId) {
177-
return Promise.reject(new TypeError(
178-
'Extension ID must be specified for screen sharing on Chrome.'));
179-
}
180-
const desktopCaptureSources = ['screen', 'window', 'tab'];
181-
if (constraints.audio) {
182-
desktopCaptureSources.push('audio');
166+
167+
// Check and convert constraints.
168+
if (!constraints.audio && !constraints.video) {
169+
return Promise.reject(new TypeError(
170+
'At least one of audio and video must be requested.'));
171+
}
172+
const mediaConstraints = Object.create({});
173+
if (typeof constraints.audio === 'object' &&
174+
constraints.audio.source === MediaFormatModule.AudioSourceInfo.MIC) {
175+
mediaConstraints.audio = Object.create({});
176+
if (utils.isEdge()) {
177+
mediaConstraints.audio.deviceId = constraints.audio.deviceId;
178+
} else {
179+
mediaConstraints.audio.deviceId = {
180+
exact: constraints.audio.deviceId,
181+
};
183182
}
184-
return new Promise((resolve, reject) => {
185-
chrome.runtime.sendMessage(
186-
constraints.extensionId, {
187-
getStream: desktopCaptureSources,
188-
},
189-
function(response) {
190-
if (response === undefined) {
191-
return reject(new Error(chrome.runtime.lastError.message));
192-
}
193-
if (constraints.audio && typeof response.options !== 'object') {
194-
Logger.warning(
195-
'Desktop sharing with audio requires the latest Chrome' +
196-
' extension. Your audio constraints will be ignored.');
197-
}
198-
const mediaConstraints = Object.create({});
199-
if (constraints.audio && (typeof response.options === 'object')) {
200-
if (response.options.canRequestAudioTrack) {
201-
mediaConstraints.audio = {
202-
mandatory: {
203-
chromeMediaSource: 'desktop',
204-
chromeMediaSourceId: response.streamId,
205-
},
206-
};
207-
} else {
208-
Logger.warning(
209-
'Sharing screen with audio was not selected by user.');
210-
}
211-
}
212-
mediaConstraints.video = Object.create({});
213-
mediaConstraints.video.mandatory = Object.create({});
214-
mediaConstraints.video.mandatory.chromeMediaSource = 'desktop';
215-
mediaConstraints.video.mandatory.chromeMediaSourceId =
216-
response.streamId;
217-
// Transform new constraint format to the old style. Because
218-
// chromeMediaSource only supported in the old style, and mix new
219-
// and old style will result type error: "Cannot use both
220-
// optional/mandatory and specific or advanced constraints.".
221-
if (constraints.video.resolution) {
222-
mediaConstraints.video.mandatory.maxHeight =
223-
mediaConstraints.video.mandatory.minHeight =
224-
constraints.video.resolution.height;
225-
mediaConstraints.video.mandatory.maxWidth =
226-
mediaConstraints.video.mandatory.minWidth =
227-
constraints.video.resolution.width;
228-
}
229-
if (constraints.video.frameRate) {
230-
mediaConstraints.video.mandatory.minFrameRate =
231-
constraints.video.frameRate;
232-
mediaConstraints.video.mandatory.maxFrameRate =
233-
constraints.video.frameRate;
234-
}
235-
resolve(navigator.mediaDevices.getUserMedia(mediaConstraints));
236-
});
237-
});
238183
} else {
239-
if (!constraints.audio && !constraints.video) {
240-
return Promise.reject(new TypeError(
241-
'At least one of audio and video must be requested.'));
184+
mediaConstraints.audio = constraints.audio;
185+
}
186+
if (typeof constraints.audio === 'object' &&
187+
constraints.audio.source ===
188+
MediaFormatModule.AudioSourceInfo.SCREENCAST) {
189+
Logger.warning(
190+
'Screen sharing with audio is not supported in Firefox.');
191+
mediaConstraints.audio = false;
192+
}
193+
if (typeof constraints.video === 'object') {
194+
mediaConstraints.video = Object.create({});
195+
if (typeof constraints.video.frameRate === 'number') {
196+
mediaConstraints.video.frameRate = constraints.video.frameRate;
242197
}
243-
const mediaConstraints = Object.create({});
244-
if (typeof constraints.audio === 'object' &&
245-
constraints.audio.source === MediaFormatModule.AudioSourceInfo.MIC) {
246-
mediaConstraints.audio = Object.create({});
247-
if (utils.isEdge()) {
248-
mediaConstraints.audio.deviceId = constraints.audio.deviceId;
249-
} else {
250-
mediaConstraints.audio.deviceId = {
251-
exact: constraints.audio.deviceId,
252-
};
253-
}
254-
} else {
255-
mediaConstraints.audio = constraints.audio;
198+
if (constraints.video.resolution &&
199+
constraints.video.resolution.width &&
200+
constraints.video.resolution.height) {
201+
mediaConstraints.video.width = Object.create({});
202+
mediaConstraints.video.width.exact =
203+
constraints.video.resolution.width;
204+
mediaConstraints.video.height = Object.create({});
205+
mediaConstraints.video.height.exact =
206+
constraints.video.resolution.height;
256207
}
257-
if (typeof constraints.audio === 'object' &&
258-
constraints.audio.source ===
259-
MediaFormatModule.AudioSourceInfo.SCREENCAST) {
260-
Logger.warning(
261-
'Screen sharing with audio is not supported in Firefox.');
262-
mediaConstraints.audio = false;
208+
if (typeof constraints.video.deviceId === 'string') {
209+
mediaConstraints.video.deviceId = { exact: constraints.video.deviceId };
263210
}
264-
if (typeof constraints.video === 'object') {
265-
mediaConstraints.video = Object.create({});
266-
if (typeof constraints.video.frameRate === 'number') {
267-
mediaConstraints.video.frameRate = constraints.video.frameRate;
268-
}
269-
if (constraints.video.resolution &&
270-
constraints.video.resolution.width &&
271-
constraints.video.resolution.height) {
272-
mediaConstraints.video.width = Object.create({});
273-
mediaConstraints.video.width.exact =
274-
constraints.video.resolution.width;
275-
mediaConstraints.video.height = Object.create({});
276-
mediaConstraints.video.height.exact =
277-
constraints.video.resolution.height;
278-
}
279-
if (typeof constraints.video.deviceId === 'string') {
280-
mediaConstraints.video.deviceId = {exact: constraints.video.deviceId};
281-
}
282-
if (utils.isFirefox() &&
283-
constraints.video.source ===
284-
MediaFormatModule.VideoSourceInfo.SCREENCAST) {
285-
mediaConstraints.video.mediaSource = 'screen';
286-
}
287-
} else {
288-
mediaConstraints.video = constraints.video;
211+
if (utils.isFirefox() &&
212+
constraints.video.source ===
213+
MediaFormatModule.VideoSourceInfo.SCREENCAST) {
214+
mediaConstraints.video.mediaSource = 'screen';
289215
}
216+
} else {
217+
mediaConstraints.video = constraints.video;
218+
}
219+
220+
if (isVideoConstrainsForScreenCast(constraints)) {
221+
return navigator.mediaDevices.getDisplayMedia(mediaConstraints);
222+
} else {
290223
return navigator.mediaDevices.getUserMedia(mediaConstraints);
291224
}
292225
}

0 commit comments

Comments
 (0)