Skip to content
This repository has been archived by the owner on May 27, 2021. It is now read-only.

Commit

Permalink
Merge pull request #5 from maruric/master
Browse files Browse the repository at this point in the history
Add one-way video streaming samples
  • Loading branch information
aikw authored Jun 28, 2016
2 parents 4b411b9 + c3b05b5 commit 7db3a55
Show file tree
Hide file tree
Showing 40 changed files with 1,484 additions and 909 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
build/
node_modules/
npm-debug.log
config.js
49 changes: 6 additions & 43 deletions README.md
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).
20 changes: 0 additions & 20 deletions gulpfile.js

This file was deleted.

1 change: 0 additions & 1 deletion samples/.gitignore

This file was deleted.

File renamed without changes.
64 changes: 0 additions & 64 deletions samples/UDCStrophe.js

This file was deleted.

7 changes: 7 additions & 0 deletions samples/common/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "airbnb",
"rules": {
"strict": 0,
"no-underscore-dangle": 0
}
}
146 changes: 146 additions & 0 deletions samples/common/UDCConnection.js
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);
}
}
Loading

0 comments on commit 7db3a55

Please sign in to comment.