This repository has been archived by the owner on May 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from maruric/master
Add one-way video streaming samples
- Loading branch information
Showing
40 changed files
with
1,484 additions
and
909 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules/ | ||
build/ | ||
node_modules/ | ||
npm-debug.log | ||
config.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,10 @@ | ||
# Ricoh Video Streaming Sample | ||
# Ricoh Video Streaming Samples | ||
|
||
Video streaming API sample app. | ||
### Two-way video streaming | ||
|
||
## Requirements | ||
* [Video Chat Sample](https://github.com/ricohapi/video-streaming-sample-app/tree/master/samples/towway). | ||
|
||
* Google Chrome 49 or newer. | ||
* Web Camera accessible from your browser. | ||
* Enable Web Camera access in your browser setting. | ||
### One-way video streaming | ||
|
||
You'll also need | ||
|
||
* Ricoh API Client Credentials (client_id & client_secret) | ||
* Ricoh ID (user_id & password) | ||
|
||
If you don't have them, please register them at [THETA Developers Website](http://contest.theta360.com/). | ||
|
||
## Setup | ||
|
||
```sh | ||
$ git clone https://github.com/ricohapi/video-streaming-sample-app.git | ||
$ cd video-streaming-sample-app | ||
$ cp samples/config_template.js samples/config.js | ||
``` | ||
|
||
and put your credentials into the `config.js`. | ||
|
||
## Build | ||
|
||
```sh | ||
$ npm install | ||
$ gulp build | ||
``` | ||
|
||
## Video Streaming | ||
|
||
Connect the Web Camera and execute `gulp run`, then the browser will be opened. | ||
Select the Web Camera, put your Ricoh ID & password, and submit the login button. | ||
Let the peer user login on his own device following the instruction above, then put the peer's User ID to the Peer-ID field and submit Connect button, then streaming connection will start between you and the peer. | ||
|
||
```sh | ||
$ gulp run | ||
``` | ||
|
||
## THETA View | ||
|
||
If the peer user is using THETA, push THETA View button, then you'll see the draggable & zoomable 360° view. | ||
* [Broadcast Sample](https://github.com/ricohapi/video-streaming-sample-app/tree/master/samples/oneway-broadcast). | ||
* [Watch Sample](https://github.com/ricohapi/video-streaming-sample-app/tree/master/samples/oneway-watch). |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "airbnb", | ||
"rules": { | ||
"strict": 0, | ||
"no-underscore-dangle": 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/* eslint no-console: ["error", { allow: ["info"] }] */ | ||
'use strict'; | ||
/* | ||
* Copyright (c) 2016 Ricoh Company, Ltd. All Rights Reserved. | ||
* See LICENSE for more information | ||
*/ | ||
|
||
export class UDCConnection { | ||
_isData(session) { | ||
return !session.audio && !session.video && !session.screen && session.data; | ||
} | ||
|
||
constructor(conn, connectCallback) { | ||
const connection = conn; | ||
|
||
connection.socket = connection.bosh; // set here, can't set on caller | ||
|
||
connection.socket.onmessage = (uid, data) => { | ||
console.info(`${data.eventName} received`); | ||
if (data.eventName === connection.socketMessageEvent) { | ||
connection.socket.onMessagesCallback(data.data); | ||
} | ||
}; | ||
|
||
connection.socket.onMessagesCallback = message => { | ||
const myJid = connection.userid.replace(/@/g, '\\40'); | ||
const toJid = message.remoteUserId.replace(/@/g, '\\40'); | ||
if (myJid !== toJid) return; | ||
|
||
const senderPeer = connection.peers[message.sender]; | ||
if (senderPeer && senderPeer.extra !== message.extra) { | ||
senderPeer.extra = message.extra; | ||
connection.onExtraDataUpdated({ userid: message.sender, extra: message.extra }); | ||
} | ||
|
||
if (message.message.streamSyncNeeded && senderPeer) { | ||
console.info('streamSyncNeeded NOT SUPPORTED'); | ||
return; | ||
} | ||
|
||
if (message.message === 'connectWithAllParticipants') { | ||
console.info('connectWithAllParticipants NOT SUPPORTED'); | ||
return; | ||
} | ||
|
||
if (message.message === 'removeFromBroadcastersList') { | ||
console.info('removeFromBroadcastersList NOT SUPPORTED'); | ||
return; | ||
} | ||
|
||
if (message.message === 'dropPeerConnection') { | ||
console.info('dropPeerConnection NOT SUPPORTED'); | ||
return; | ||
} | ||
|
||
if (message.message.allParticipants) { | ||
console.info('allParticipants NOT SUPPORTED'); | ||
return; | ||
} | ||
|
||
if (message.message.newParticipant) { | ||
console.info('newParticipant NOT SUPPORTED'); | ||
return; | ||
} | ||
|
||
if (message.message.readyForOffer || message.message.addMeAsBroadcaster) { | ||
connection.addNewBroadcaster(message.sender); | ||
} | ||
|
||
if (message.message.newParticipationRequest && message.sender !== connection.userid) { | ||
if (senderPeer) connection.deletePeer(message.sender); | ||
|
||
const offerAudio = connection.sdpConstraints.mandatory.OfferToReceiveAudio; | ||
const offerVideo = connection.sdpConstraints.mandatory.OfferToReceiveVideo; | ||
const ses = connection.session; | ||
const msg = message.message; | ||
const noRemoteSdp = { OfferToReceiveAudio: offerAudio, OfferToReceiveVideo: offerVideo }; | ||
const oneLocalSdp = { OfferToReceiveAudio: !!ses.audio, OfferToReceiveVideo: !!ses.video }; | ||
const noLocalSdp = ses.oneway ? oneLocalSdp : noRemoteSdp; | ||
const rOneWay = !!ses.oneway || connection.direction === 'one-way'; | ||
const noNeedRemoteStream = typeof msg.isOneWay !== 'undefined' ? msg.isOneWay : rOneWay; | ||
|
||
const userPref = { | ||
extra: message.extra || {}, | ||
localPeerSdpConstraints: msg.remotePeerSdpConstraints || noRemoteSdp, | ||
remotePeerSdpConstraints: msg.localPeerSdpConstraints || noLocalSdp, | ||
isOneWay: noNeedRemoteStream, | ||
dontGetRemoteStream: noNeedRemoteStream, | ||
isDataOnly: typeof msg.isDataOnly !== 'undefined' ? msg.isDataOnly : this._isData(ses), | ||
dontAttachLocalStream: !!msg.dontGetRemoteStream, | ||
connectionDescription: message, | ||
successCallback: () => { | ||
if (noNeedRemoteStream || rOneWay || this._isData(connection.session)) { | ||
connection.addNewBroadcaster(message.sender, userPref); | ||
} | ||
}, | ||
}; | ||
connection.onNewParticipant(message.sender, userPref); | ||
return; | ||
} | ||
|
||
if (message.message.shiftedModerationControl) { | ||
console.info('shiftedModerationControl NOT SUPPORTED'); | ||
return; | ||
} | ||
|
||
if (message.message.changedUUID) { | ||
console.info('changedUUID NOT SUPPORTED'); | ||
// no return | ||
} | ||
|
||
if (message.message.userLeft) { | ||
connection.multiPeersHandler.onUserLeft(message.sender); | ||
if (!!message.message.autoCloseEntireSession) { | ||
connection.leave(); | ||
} | ||
return; | ||
} | ||
|
||
connection.multiPeersHandler.addNegotiatedMessage(message.message, message.sender); | ||
}; | ||
|
||
|
||
connection.socket.emit = (eventName, data, callback) => { | ||
if (eventName === 'changed-uuid') return; | ||
if (eventName === 'message') { | ||
// data:uid, callback:data on boshclient | ||
connection.socket.onmessage(data, JSON.parse(callback)); | ||
return; | ||
} | ||
if (typeof data === 'undefined') return; | ||
if (data.message && data.message.shiftedModerationControl) return; | ||
|
||
if (eventName === 'disconnect-with') { | ||
if (connection.peers[data]) { | ||
connection.peers[data].peer.close(); | ||
} | ||
return; | ||
} | ||
connection.socket.send(data.remoteUserId, JSON.stringify({ eventName, data })); | ||
console.info(`${eventName} sended`); | ||
if (callback) { callback(); } | ||
}; | ||
connectCallback(connection.socket); | ||
} | ||
} |
Oops, something went wrong.