diff --git a/lib/account.js b/lib/account.js index 2a678c9..af0c00a 100644 --- a/lib/account.js +++ b/lib/account.js @@ -1,134 +1,134 @@ 'use strict'; import debug from 'debug'; import transform from 'sdp-transform'; +import md5 from 'blueimp-md5'; -import { md5 } from 'blueimp-md5'; import { EventEmitter } from 'events'; import { Call, Identity } from './call'; const DEBUG = debug('sylkrtc:Account'); class Account extends EventEmitter { constructor(options, connection) { if (options.account.indexOf('@') === -1) { throw new Error('Invalid account id specified'); } super(); const id = options.account; const [username, domain] = id.split('@'); this._id = id; this._displayName = options.displayName; this._password = md5(username + ':' + (options.realm || domain)+ ':' + options.password); this._connection = connection; this._registrationState = null; this._calls = new Map(); } get id() { return this._id; } get password() { return this._password; } get displayName() { return this._displayName; } get registrationState() { return this._registrationState; } register() { let req = { sylkrtc: 'account-register', account: this._id }; this._sendRequest(req, (error) => { if (error) { DEBUG('Register error: %s', error); const oldState = this._registrationState; const newState = 'failed'; let data = {reason: error.toString()}; this._registrationState = newState; this.emit('registrationStateChanged', oldState, newState, data); } }); } unregister() { let req = { sylkrtc: 'account-unregister', account: this._id, }; this._sendRequest(req, (error) => { if (error) { DEBUG('Unregister error: %s', error); } const oldState = this._registrationState; const newState = null; this._registrationState = newState; this.emit('registrationStateChanged', oldState, newState, {}); }); } call(uri, options={}) { let callObj = new Call(this); callObj._initOutgoing(uri, options); this._calls.set(callObj.id, callObj); this.emit('outgoingCall', callObj); return callObj; } // Private API _handleEvent(message) { DEBUG('Received account event: %s', message.event); let data = {}; switch (message.event) { case 'registration_state': const oldState = this._registrationState; const newState = message.data.state; this._registrationState = newState; if (newState === 'failed') { data.reason = message.data.reason; } this.emit('registrationStateChanged', oldState, newState, data); break; case 'incoming_session': let call = new Call(this); call._initIncoming(message.session, message.data.originator, message.data.sdp); this._calls.set(call.id, call); // see what media types are offered let mediaTypes = { audio: false, video: false }; const parsedSdp = transform.parse(message.data.sdp); for (let media of parsedSdp.media) { if (media.type === 'audio' && media.port !== 0 && media.direction === 'sendrecv') { mediaTypes.audio = true; } else if (media.type === 'video' && media.port !== 0 && media.direction === 'sendrecv') { mediaTypes.video = true; } } DEBUG('Incoming call from %s with media types: %o', message.data.originator.uri, mediaTypes); this.emit('incomingCall', call, mediaTypes); break; case 'missed_session': data.originator = new Identity(message.data.originator.uri, message.data.originator.display_name); this.emit('missedCall', data); break; default: break; } } _sendRequest(req, cb) { this._connection._sendRequest(req, cb); } } export { Account }; diff --git a/package.json b/package.json index 0dc5ca2..a0d70bd 100644 --- a/package.json +++ b/package.json @@ -1,46 +1,46 @@ { "name": "sylkrtc", "version": "0.6.1", "main": "lib/sylkrtc.js", "description": "SylkServer WebRTC Gateway client library", "repository": { "type": "git", "url": "git://github.com/AGProjects/sylkrtc.git" }, "keywords": [], "author": "AG Projects", "contributors": [ "Tijmen de Mes ", "Saúl Ibarra Corretgé " ], "license": "MIT", "readmeFilename": "README.md", "browserify": { "transform": [ "babelify" ] }, "dependencies": { - "blueimp-md5": "^1.1.1", + "blueimp-md5": "^2.3.0", "debug": "^2.2.0", "node-uuid": "^1.4.7", - "rtcninja": "^0.6.4", - "sdp-transform": "^1.5.3", - "websocket": "^1.0.22" + "rtcninja": "^0.6.6", + "sdp-transform": "^1.6.2", + "websocket": "^1.0.23" }, "devDependencies": { - "babel-preset-es2015": "^6.1.18", - "babelify": "^7.2.0", - "browserify": "^12.0.1", + "babel-preset-es2015": "^6.9.0", + "babelify": "^7.3.0", + "browserify": "^13.0.1", "gulp": "git+https://github.com/gulpjs/gulp.git#4.0", "gulp-filelog": "^0.4.1", - "gulp-header": "^1.7.1", - "gulp-jshint": "^2.0.0", + "gulp-header": "^1.8.2", + "gulp-jshint": "^2.0.1", "gulp-sourcemaps": "^1.6.0", - "gulp-uglify": "^1.5.1", + "gulp-uglify": "^1.5.3", "gulp-util": "^3.0.7", - "jshint-stylish": "^2.1.0", + "jshint-stylish": "^2.2.0", "vinyl-buffer": "^1.0.0", "vinyl-source-stream": "^1.1.0" } }