Comparing version 1.1.0 to 1.2.0
/* | ||
* Orange ocast-sdk | ||
* version : 1.1.0 | ||
* version : 1.2.0 | ||
* Copyright (C) 2017 Orange | ||
@@ -189,2 +189,27 @@ */ | ||
/** | ||
* Enum Transport | ||
*/ | ||
(function (EnumTransport) { | ||
EnumTransport["REPLY"] = "reply"; | ||
EnumTransport["COMMAND"] = "command"; | ||
EnumTransport["EVENT"] = "event"; | ||
})(exports.EnumTransport || (exports.EnumTransport = {})); | ||
/* | ||
* Copyright 2017 Orange | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/** | ||
* Transport Class | ||
@@ -264,27 +289,2 @@ */ | ||
*/ | ||
/** | ||
* Enum Transport | ||
*/ | ||
var EnumTransport; | ||
(function (EnumTransport) { | ||
EnumTransport["REPLY"] = "reply"; | ||
EnumTransport["COMMAND"] = "command"; | ||
EnumTransport["EVENT"] = "event"; | ||
})(EnumTransport || (EnumTransport = {})); | ||
/* | ||
* Copyright 2017 Orange | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
class Logger { | ||
@@ -386,61 +386,73 @@ constructor() { | ||
class Channel { | ||
/** | ||
* Represents a Channel. | ||
* @constructor | ||
* @param {string} name - The service name of the channel, used to route the message. | ||
*/ | ||
constructor(name) { | ||
this.name = name; | ||
this.ws = null; | ||
} | ||
setSocket(websocket) { | ||
this.ws = websocket; | ||
} | ||
/** | ||
* Method used to notify a new message for this Channel | ||
* @param {Transport} transport - message received | ||
*/ | ||
onMessage(transport) { | ||
Log.warn(TAG + "onMessage need to be implemented for namespace " + this.name); | ||
this.sendReply(transport.id, transport.src, { params: { code: exports.EnumError.NO_IMPLEMENTATION } }); | ||
} | ||
/** | ||
* send Reply Command | ||
* @param {number} id - Request identifier | ||
* @param {string} dst - Destination identifier | ||
* @param {any} data - Data of the reply | ||
*/ | ||
sendReply(id, dst, data) { | ||
const message = new Transport(UUID, dst, EnumTransport.REPLY, id, new TransportMessage(this.name, data)); | ||
message.setStatus("OK"); | ||
Log.debug(TAG + "sendReply : " + JSON.stringify(message)); | ||
this.sendMessage(message); | ||
} | ||
/** | ||
* sendEvent | ||
* @param {any} data - Data of the event | ||
*/ | ||
sendEvent(data) { | ||
const message = new Transport(UUID, WILDCARD, EnumTransport.EVENT, Channel.sequenceMessage++, new TransportMessage(this.name, data)); | ||
Log.debug(TAG + "sendEvent : " + JSON.stringify(message)); | ||
this.sendMessage(message); | ||
} | ||
/** | ||
* send command event | ||
* @param {string} dst - Destination identifier | ||
* @param {any} data - Data of the command | ||
*/ | ||
sendCommand(dst, data) { | ||
const message = new Transport(UUID, dst, EnumTransport.COMMAND, Channel.sequenceMessage++, new TransportMessage(this.name, data)); | ||
Log.debug(TAG + "sendCommand : " + JSON.stringify(message)); | ||
this.sendMessage(message); | ||
} | ||
/** | ||
* Send Transport : Basic Command | ||
* @param {Transport} message - Message to send | ||
* @private | ||
*/ | ||
sendMessage(message) { | ||
this.ws.send(JSON.stringify(message)); | ||
} | ||
/** | ||
* Represents a Channel. | ||
* @constructor | ||
* @param {string} name - The service name of the channel, used to route the message. | ||
*/ | ||
constructor(name) { | ||
this.name = name; | ||
this.waitingReplies = {}; | ||
this.ws = null; | ||
} | ||
setSocket(websocket) { | ||
this.ws = websocket; | ||
} | ||
/** | ||
* Method used to notify a new message for this Channel | ||
* @param {Transport} transport - message received | ||
*/ | ||
onMessage(transport) { | ||
if (transport.type === exports.EnumTransport.REPLY) { | ||
const id = transport.id; | ||
if (this.waitingReplies[id]) { | ||
this.waitingReplies[id](transport.message.data); | ||
delete this.waitingReplies[id]; | ||
} | ||
return; | ||
} | ||
Log.warn(TAG + "onMessage need to be implemented for namespace " + this.name); | ||
this.sendReply(transport.id, transport.src, { params: { code: exports.EnumError.NO_IMPLEMENTATION } }); | ||
} | ||
/** | ||
* send Reply Command | ||
* @param {number} id - Request identifier | ||
* @param {string} dst - Destination identifier | ||
* @param {any} data - Data of the reply | ||
*/ | ||
sendReply(id, dst, data) { | ||
const message = new Transport(UUID, dst, exports.EnumTransport.REPLY, id, new TransportMessage(this.name, data)); | ||
message.setStatus("OK"); | ||
Log.debug(TAG + "sendReply : " + JSON.stringify(message)); | ||
this.sendMessage(message); | ||
} | ||
/** | ||
* sendEvent | ||
* @param {any} data - Data of the event | ||
*/ | ||
sendEvent(data) { | ||
const message = new Transport(UUID, WILDCARD, exports.EnumTransport.EVENT, Channel.sequenceMessage++, new TransportMessage(this.name, data)); | ||
Log.debug(TAG + "sendEvent : " + JSON.stringify(message)); | ||
this.sendMessage(message); | ||
} | ||
/** | ||
* send command event | ||
* @param {string} dst - Destination identifier | ||
* @param {any} data - Data of the command | ||
*/ | ||
sendCommand(dst, data) { | ||
const message = new Transport(UUID, dst, exports.EnumTransport.COMMAND, Channel.sequenceMessage++, new TransportMessage(this.name, data)); | ||
Log.debug(TAG + "sendCommand : " + JSON.stringify(message)); | ||
return new Promise((resolve, reject) => { | ||
this.waitingReplies[message.id] = resolve; | ||
this.sendMessage(message); | ||
}); | ||
} | ||
/** | ||
* Send Transport : Basic Command | ||
* @param {Transport} message - Message to send | ||
* @private | ||
*/ | ||
sendMessage(message) { | ||
this.ws.send(JSON.stringify(message)); | ||
} | ||
} | ||
@@ -1187,3 +1199,3 @@ Channel.sequenceMessage = 1; | ||
Log$1.error(TAG$1 + "Message type '" + transport.message.data.name + "' unknown"); | ||
if (transport.type === EnumTransport.COMMAND) { | ||
if (transport.type === exports.EnumTransport.COMMAND) { | ||
this.sendReply(transport.id, transport.src, { | ||
@@ -1224,3 +1236,3 @@ name: transport.message.data.name, | ||
Log$1.error(TAG$1 + "Error while executing " + methodDescriptor.methodName + " paramters missing)"); | ||
if (transport.type === EnumTransport.COMMAND) { | ||
if (transport.type === exports.EnumTransport.COMMAND) { | ||
this.sendReply(transport.id, transport.src, { | ||
@@ -1247,3 +1259,3 @@ name: transport.message.data.name, | ||
Log$1.error(TAG$1 + "Error while executing " + methodDescriptor.methodName + " with error ", e); | ||
if (transport.type === EnumTransport.COMMAND) { | ||
if (transport.type === exports.EnumTransport.COMMAND) { | ||
this.sendReply(transport.id, transport.src, { | ||
@@ -1264,3 +1276,3 @@ name: transport.message.data.name, | ||
Log$1.error(TAG$1 + "Error while executing " + methodDescriptor.methodName + " with error ", e); | ||
if (transport.type === EnumTransport.COMMAND) { | ||
if (transport.type === exports.EnumTransport.COMMAND) { | ||
this.sendReply(transport.id, transport.src, { | ||
@@ -1700,2 +1712,9 @@ name: transport.message.data.name, | ||
*/ | ||
setupChannel(channel) { | ||
this.channels[channel.name] = channel; | ||
} | ||
/** | ||
* Initialize MediaChannel | ||
* @private | ||
*/ | ||
setupMediaChannel() { | ||
@@ -1724,3 +1743,3 @@ let channel = new MediaChannel(); | ||
Log$5.warn("Unknown namespace <<<" + transport.message.service + ">>>"); | ||
let message = new Transport(transport.dst, transport.src, EnumTransport.REPLY, transport.id, new TransportMessage(transport.message.service, { | ||
let message = new Transport(transport.dst, transport.src, exports.EnumTransport.REPLY, transport.id, new TransportMessage(transport.message.service, { | ||
params: { code: exports.EnumError.INVALID_NAMESPACE } | ||
@@ -1738,3 +1757,3 @@ })); | ||
Log$5.debug(TAG$4 + "receive message : " + event.data); | ||
if (event.data.type === EnumTransport.REPLY && event.data.status !== "ok") { | ||
if (event.data.type === exports.EnumTransport.REPLY && event.data.status !== "ok") { | ||
Log$5.error(TAG$4 + "receive error message : " + event.data.status); | ||
@@ -1741,0 +1760,0 @@ return; |
@@ -8,2 +8,3 @@ import { Transport } from "../protocol/transport"; | ||
protected static sequenceMessage: number; | ||
private waitingReplies; | ||
private ws; | ||
@@ -39,3 +40,3 @@ /** | ||
*/ | ||
protected sendCommand(dst: string, data: any): void; | ||
protected sendCommand(dst: string, data: any): Promise<{}>; | ||
/** | ||
@@ -42,0 +43,0 @@ * Send Transport : Basic Command |
@@ -7,2 +7,3 @@ import "./channel/media.notifier"; | ||
export { EnumTransferMode } from "./type/enum.transfermode"; | ||
export { EnumTransport } from "./type/enum.transport"; | ||
export { Channel } from "./channel/channel"; | ||
@@ -9,0 +10,0 @@ export { MediaChannel } from "./channel/media.channel"; |
@@ -52,2 +52,7 @@ import { Channel } from "./channel/channel"; | ||
*/ | ||
setupChannel(channel: Channel): void; | ||
/** | ||
* Initialize MediaChannel | ||
* @private | ||
*/ | ||
private setupMediaChannel; | ||
@@ -54,0 +59,0 @@ /** |
{ | ||
"name": "ocast-sdk", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"engines": { | ||
@@ -5,0 +5,0 @@ "node": ">=8.6.0" |
@@ -17,3 +17,2 @@ /* | ||
import {OCast} from "../ocast"; | ||
import {Transport} from "../protocol/transport"; | ||
@@ -36,2 +35,3 @@ import {TransportMessage} from "../protocol/transport.message"; | ||
protected static sequenceMessage: number = 1; | ||
private waitingReplies: {[key: string]: (transport: Transport) => void} = {}; | ||
@@ -57,2 +57,10 @@ private ws: WebSocket = null; | ||
public onMessage(transport: Transport) { | ||
if (transport.type === EnumTransport.REPLY) { | ||
const id = transport.id; | ||
if (this.waitingReplies[id]) { | ||
this.waitingReplies[id](transport.message.data); | ||
delete this.waitingReplies[id]; | ||
} | ||
return; | ||
} | ||
Log.warn(TAG + "onMessage need to be implemented for namespace " + this.name); | ||
@@ -95,3 +103,6 @@ this.sendReply(transport.id, transport.src, {params: {code: EnumError.NO_IMPLEMENTATION}}); | ||
Log.debug(TAG + "sendCommand : " + JSON.stringify(message)); | ||
this.sendMessage(message); | ||
return new Promise((resolve, reject) => { | ||
this.waitingReplies[message.id] = resolve; | ||
this.sendMessage(message); | ||
}); | ||
} | ||
@@ -98,0 +109,0 @@ |
@@ -18,19 +18,20 @@ /* | ||
export {EnumError} from "./type/enum.error"; | ||
export {EnumMediaStatus} from "./type/enum.media.status"; | ||
export {EnumMedia} from "./type/enum.media"; | ||
export {EnumTrack} from "./type/enum.track"; | ||
export {EnumTransferMode} from "./type/enum.transfermode"; | ||
export {Channel} from "./channel/channel"; | ||
export {MediaChannel} from "./channel/media.channel"; | ||
export {WebappChannel} from "./channel/webapp.channel"; | ||
export {Media} from "./media/media"; | ||
export {IMediaNotifier} from "./channel/media.notifier"; | ||
export {VideoMedia} from "./media/video.media"; | ||
export {ImageMedia} from "./media/image.media"; | ||
export {PlaybackStatus} from "./protocol/playback.status"; | ||
export {Metadata} from "./protocol/metadata"; | ||
export {VideoPlaybackStatus} from "./media/video.playback.status"; | ||
export {Logger} from "./util/logger"; | ||
export {OCast} from "./ocast"; | ||
export { EnumError } from "./type/enum.error"; | ||
export { EnumMediaStatus } from "./type/enum.media.status"; | ||
export { EnumMedia } from "./type/enum.media"; | ||
export { EnumTrack } from "./type/enum.track"; | ||
export { EnumTransferMode } from "./type/enum.transfermode"; | ||
export { EnumTransport } from "./type/enum.transport"; | ||
export { Channel } from "./channel/channel"; | ||
export { MediaChannel } from "./channel/media.channel"; | ||
export { WebappChannel } from "./channel/webapp.channel"; | ||
export { Media } from "./media/media"; | ||
export { IMediaNotifier } from "./channel/media.notifier"; | ||
export { VideoMedia } from "./media/video.media"; | ||
export { ImageMedia } from "./media/image.media"; | ||
export { PlaybackStatus } from "./protocol/playback.status"; | ||
export { Metadata } from "./protocol/metadata"; | ||
export { VideoPlaybackStatus } from "./media/video.playback.status"; | ||
export { Logger } from "./util/logger"; | ||
export { OCast } from "./ocast"; | ||
export { Transport } from "./protocol/transport"; |
@@ -111,2 +111,9 @@ /* | ||
*/ | ||
public setupChannel(channel: Channel): void { | ||
this.channels[channel.name] = channel; | ||
} | ||
/** | ||
* Initialize MediaChannel | ||
* @private | ||
*/ | ||
private setupMediaChannel() { | ||
@@ -113,0 +120,0 @@ let channel = new MediaChannel(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
633746
8445