UNPKG

@simplito/privmx-webendpoint

Version:

PrivMX Web Endpoint library

143 lines (140 loc) 6.45 kB
"use strict"; /*! PrivMX Web Endpoint. Copyright © 2024 Simplito sp. z o.o. This file is part of the PrivMX Platform (https://privmx.dev). This software is Licensed under the PrivMX Free License. See the License for the specific language governing permissions and limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.StreamApiNative = void 0; const WebRtcInterfaceImpl_1 = require("../webStreams/WebRtcInterfaceImpl"); const BaseNative_1 = require("./BaseNative"); class StreamApiNative extends BaseNative_1.BaseNative { webRtcClient; static bindingId = -1; static getBindingId() { return ++this.bindingId; } webRtcInterfacePtr = -1; selfPtr = -1; webRtcInterfaceImpl; constructor(api, webRtcClient) { super(api); this.webRtcClient = webRtcClient; webRtcClient.bindApiInterface({ trickle: (sessionId, candidate) => { return this.trickle(this.selfPtr, [sessionId, candidate]); }, acceptOffer: (sessionId, sdp) => { return this.acceptOfferOnReconfigure(this.selfPtr, [sessionId, sdp]); }, }); } async newApi(connectionPtr, eventApiPtr) { const bindingId = StreamApiNative.getBindingId(); this.bindWebRtcInterfaceAsHandler(bindingId); this.selfPtr = await this.runAsync((taskId) => this.api.lib.StreamApi_newStreamApi(taskId, connectionPtr, eventApiPtr, bindingId)); return this.selfPtr; } async deleteApi(ptr) { await this.runAsync((taskId) => this.api.lib.StreamApi_deleteStreamApi(taskId, ptr)); this.deleteApiRef(); } async create(ptr, args) { return this.runAsync((taskId) => this.api.lib.StreamApi_create(taskId, ptr, args)); } async createStreamRoom(ptr, args) { return this.runAsync((taskId) => this.api.lib.StreamApi_createStreamRoom(taskId, ptr, args)); } async updateStreamRoom(ptr, args) { return this.runAsync((taskId) => this.api.lib.StreamApi_updateStreamRoom(taskId, ptr, args)); } async deleteStreamRoom(ptr, args) { return this.runAsync((taskId) => this.api.lib.StreamApi_deleteStreamRoom(taskId, ptr, args)); } async getStreamRoom(ptr, args) { return this.runAsync((taskId) => this.api.lib.StreamApi_getStreamRoom(taskId, ptr, args)); } async listStreamRooms(ptr, args) { return this.runAsync((taskId) => this.api.lib.StreamApi_listStreamRooms(taskId, ptr, args)); } async createStream(ptr, args) { // params from api: streamRoomId, streamId // params to lib: streamRoomId, streamId, webrtcInterfacePtr // const libArgs: [string, number, number] = [...args, this.webRtcInterfacePtr]; return this.runAsync((taskId) => this.api.lib.StreamApi_createStream(taskId, ptr, args)); } async joinStreamRoom(ptr, args) { return this.runAsync((taskId) => this.api.lib.StreamApi_joinStreamRoom(taskId, ptr, args)); } async leaveStreamRoom(ptr, args) { return this.runAsync((taskId) => this.api.lib.StreamApi_leaveStreamRoom(taskId, ptr, args)); } async enableStreamRoomRecording(ptr, args) { return this.runAsync((taskId) => this.api.lib.StreamApi_enableStreamRoomRecording(taskId, ptr, args)); } async getStreamRoomRecordingKeys(ptr, args) { return this.runAsync((taskId) => this.api.lib.StreamApi_getStreamRoomRecordingKeys(taskId, ptr, args)); } async publishStream(ptr, args) { const ret = await this.runAsync((taskId) => this.api.lib.StreamApi_publishStream(taskId, ptr, args)); return ret; } async updateStream(ptr, args) { const ret = await this.runAsync((taskId) => this.api.lib.StreamApi_updateStream(taskId, ptr, args)); return ret; } async unpublishStream(ptr, args) { return this.runAsync((taskId) => this.api.lib.StreamApi_unpublishStream(taskId, ptr, args)); } async listStreams(ptr, args) { return this.runAsync((taskId) => this.api.lib.StreamApi_listStreams(taskId, ptr, args)); } async subscribeToRemoteStreams(ptr, args) { return this.runAsync((taskId) => this.api.lib.StreamApi_subscribeToRemoteStreams(taskId, ptr, args)); } async modifyRemoteStreamsSubscriptions(ptr, args) { return this.runAsync((taskId) => this.api.lib.StreamApi_modifyRemoteStreamsSubscriptions(taskId, ptr, args)); } async unsubscribeFromRemoteStreams(ptr, args) { return this.runAsync((taskId) => this.api.lib.StreamApi_unsubscribeFromRemoteStreams(taskId, ptr, args)); } async keyManagement(ptr, args) { return this.runAsync((taskId) => this.api.lib.StreamApi_keyManagement(taskId, ptr, args)); } async getTurnCredentials(ptr, args) { return this.runAsync((taskId) => this.api.lib.StreamApi_getTurnCredentials(taskId, ptr, args)); } async subscribeFor(ptr, args) { return this.runAsync((taskId) => this.api.lib.StreamApi_subscribeFor(taskId, ptr, args)); } async unsubscribeFrom(ptr, args) { return this.runAsync((taskId) => this.api.lib.StreamApi_unsubscribeFrom(taskId, ptr, args)); } async buildSubscriptionQuery(ptr, args) { return this.runAsync((taskId) => this.api.lib.StreamApi_buildSubscriptionQuery(taskId, ptr, args)); } async trickle(ptr, args) { const [sessionId, candidate] = args; const convertedArgs = [sessionId, JSON.stringify(candidate)]; return this.runAsync((taskId) => this.api.lib.StreamApi_trickle(taskId, ptr, convertedArgs)); } async acceptOfferOnReconfigure(ptr, args) { return this.runAsync((taskId) => this.api.lib.StreamApi_acceptOfferOnReconfigure(taskId, ptr, args)); } async setNewOfferOnReconfigure(ptr, args) { return this.runAsync((taskId) => this.api.lib.StreamApi_setNewOfferOnReconfigure(taskId, ptr, args)); } bindWebRtcInterfaceAsHandler(bindingId) { this.webRtcInterfaceImpl = new WebRtcInterfaceImpl_1.WebRtcInterfaceImpl(this.webRtcClient); let windowBinder = window.webRtcInterfaceToNativeHandler; if (!windowBinder) { windowBinder = {}; } windowBinder[bindingId] = this.webRtcInterfaceImpl; window.webRtcInterfaceToNativeHandler = windowBinder; } } exports.StreamApiNative = StreamApiNative;