Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
10583d0
commit c6bf746
Showing
7 changed files
with
164 additions
and
6 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
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,62 @@ | ||
/** | ||
* Created by guhao on 2017/7/24. | ||
*/ | ||
'use strict'; | ||
|
||
var Pili = require('../index.js'); | ||
|
||
// ======================== Configurations ========================= | ||
// Replace with your keys here | ||
var ACCESS_KEY = 'FMVCRs2-LO1ivRNi4l7mEZE6ZDvPv-519D12kZCO'; | ||
var SECRET_KEY = 'InOXBls8alaPiRcFn002XsoXKFw1iFJZxcoOvAeY'; | ||
|
||
// Replace with your hub name | ||
var HUB = 'qiniu-pili-test'; // The Hub must be exists before use | ||
|
||
|
||
/** | ||
* Instantiate a Pili rtc object | ||
*/ | ||
var credentials = new Pili.Credentials(ACCESS_KEY, SECRET_KEY); | ||
var rtc = new Pili.RTCV2(credentials); | ||
|
||
var roomName = "room1"; | ||
var ownerID = 'ownerID'; | ||
rtc.createRoom(ownerID, roomName, {}, function(err, roomInfo) { | ||
if (!err) { | ||
console.log("success") | ||
console.log(roomInfo) | ||
} else { | ||
console.log("oops") | ||
console.log(err) | ||
} | ||
}) | ||
|
||
rtc.getRoom(roomName, function(err, roomInfo) { | ||
if (!err) { | ||
console.log("success") | ||
console.log(roomInfo) | ||
} else { | ||
console.log("oops") | ||
console.log(err) | ||
} | ||
}) | ||
|
||
rtc.deleteRoom(roomName, function(err) { | ||
if (!err) { | ||
console.log("success") | ||
console.log("delete OK") | ||
} else { | ||
console.log("oops") | ||
console.log(err) | ||
} | ||
}) | ||
|
||
|
||
var roomToken = rtc.roomToken({ | ||
"version": "2.0", | ||
"room_name": roomName, | ||
"user_id": ownerID, | ||
"perm": "user" | ||
}) | ||
console.log(roomToken); |
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
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
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
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
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,47 @@ | ||
'use strict'; | ||
|
||
const API = require('./api'); | ||
|
||
function RTCV2(credentials) { | ||
this.credentials = credentials; | ||
|
||
API.init(); | ||
} | ||
|
||
RTCV2.prototype.createRoom = function(ownerID, roomName, options, fn) { | ||
|
||
return API.createRtcRoomV2(this.credentials, ownerID, roomName, options, fn); | ||
} | ||
|
||
RTCV2.prototype.getRoom = function(roomName, fn) { | ||
|
||
return API.getRtcRoomV2(this.credentials, roomName, fn); | ||
} | ||
|
||
RTCV2.prototype.deleteRoom = function(roomName, fn) { | ||
|
||
return API.deleteRtcRoomV2(this.credentials, roomName, fn); | ||
} | ||
|
||
RTCV2.prototype.roomToken = function(roomAccess) { | ||
|
||
/* | ||
roomAccess = { | ||
"version": "2.0" | ||
"room_name": "<RoomName>", | ||
"user_id": "<UserID>", | ||
"perm": "<Permission>", | ||
"expire_at": <ExpireAt> | ||
} | ||
*/ | ||
|
||
if (!roomAccess.expire_at) { | ||
roomAccess.expire_at = Math.floor(Date.now() / 1000) + 1800; | ||
} | ||
|
||
return this.credentials.signJson(roomAccess); | ||
} | ||
|
||
|
||
|
||
module.exports = exports = RTCV2; |