UNPKG

@sendbird/calls-react-native

Version:

Sendbird Calls SDK for React Native: Empower React Native apps with seamless audio, video, and group calling. Build interactive communication easily.

111 lines (108 loc) 6.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = exports.GroupCallEventType = exports.DirectCallEventType = exports.DefaultEventType = exports.CallsEvent = void 0; var _reactNative = require("react-native"); var _constants = require("../utils/constants"); var _converter = require("../utils/converter"); var _logger = require("../utils/logger"); var _JSEventEmitter = _interopRequireDefault(require("./JSEventEmitter")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } /* eslint-disable */ const MODULE_NAME = 'RNSendbirdCalls'; const NativeModule = _reactNative.NativeModules[MODULE_NAME]; //TurboModuleRegistry.get<SendbirdCallsSpec>(MODULE_NAME); const NoopModuleProxy = new Proxy({}, { get() { throw new Error(_constants.LINKING_ERROR); } }); let CallsEvent = exports.CallsEvent = /*#__PURE__*/function (CallsEvent) { CallsEvent["DEFAULT"] = "sendbird.call.default"; CallsEvent["DIRECT_CALL"] = "sendbird.call.direct"; CallsEvent["GROUP_CALL"] = "sendbird.call.group"; return CallsEvent; }({}); let DefaultEventType = exports.DefaultEventType = /*#__PURE__*/function (DefaultEventType) { DefaultEventType["ON_RINGING"] = "sendbird.call.default.onRinging"; return DefaultEventType; }({}); let DirectCallEventType = exports.DirectCallEventType = /*#__PURE__*/function (DirectCallEventType) { DirectCallEventType["ON_ESTABLISHED"] = "sendbird.call.direct.onEstablished"; DirectCallEventType["ON_CONNECTED"] = "sendbird.call.direct.onConnected"; DirectCallEventType["ON_RECONNECTING"] = "sendbird.call.direct.onReconnecting"; DirectCallEventType["ON_RECONNECTED"] = "sendbird.call.direct.onReconnected"; DirectCallEventType["ON_ENDED"] = "sendbird.call.direct.onEnded"; DirectCallEventType["ON_REMOTE_AUDIO_SETTINGS_CHANGED"] = "sendbird.call.direct.onRemoteAudioSettingsChanged"; DirectCallEventType["ON_REMOTE_VIDEO_SETTINGS_CHANGED"] = "sendbird.call.direct.onRemoteVideoSettingsChanged"; DirectCallEventType["ON_LOCAL_VIDEO_SETTINGS_CHANGED"] = "sendbird.call.direct.onLocalVideoSettingsChanged"; DirectCallEventType["ON_REMOTE_RECORDING_STATUS_CHANGED"] = "sendbird.call.direct.onRemoteRecordingStatusChanged"; DirectCallEventType["ON_AUDIO_DEVICE_CHANGED"] = "sendbird.call.direct.onAudioDeviceChanged"; DirectCallEventType["ON_CUSTOM_ITEMS_UPDATED"] = "sendbird.call.direct.onCustomItemsUpdated"; DirectCallEventType["ON_CUSTOM_ITEMS_DELETED"] = "sendbird.call.direct.onCustomItemsDeleted"; DirectCallEventType["ON_USER_HOLD_STATUS_CHANGED"] = "sendbird.call.direct.onUserHoldStatusChanged"; return DirectCallEventType; }({}); let GroupCallEventType = exports.GroupCallEventType = /*#__PURE__*/function (GroupCallEventType) { GroupCallEventType["ON_DELETED"] = "sendbird.call.group.onDeleted"; GroupCallEventType["ON_ERROR"] = "sendbird.call.group.onError"; GroupCallEventType["ON_LOCAL_PARTICIPANT_DISCONNECTED"] = "sendbird.call.group.onLocalParticipantDisconnected"; GroupCallEventType["ON_LOCAL_PARTICIPANT_RECONNECTED"] = "sendbird.call.group.onLocalParticipantReconnected"; GroupCallEventType["ON_REMOTE_PARTICIPANT_ENTERED"] = "sendbird.call.group.onRemoteParticipantEntered"; GroupCallEventType["ON_REMOTE_PARTICIPANT_EXITED"] = "sendbird.call.group.onRemoteParticipantExited"; GroupCallEventType["ON_REMOTE_PARTICIPANT_STREAM_STARTED"] = "sendbird.call.group.onRemoteParticipantStreamStarted"; GroupCallEventType["ON_AUDIO_DEVICE_CHANGED"] = "sendbird.call.group.onAudioDeviceChanged"; GroupCallEventType["ON_REMOTE_VIDEO_SETTINGS_CHANGED"] = "sendbird.call.group.onRemoteVideoSettingsChanged"; GroupCallEventType["ON_REMOTE_AUDIO_SETTINGS_CHANGED"] = "sendbird.call.group.onRemoteAudioSettingsChanged"; GroupCallEventType["ON_CUSTOM_ITEMS_UPDATED"] = "sendbird.call.group.onCustomItemsUpdated"; GroupCallEventType["ON_CUSTOM_ITEMS_DELETED"] = "sendbird.call.group.onCustomItemsDeleted"; return GroupCallEventType; }({}); class NativeBinder { get nativeModule() { return this._nativeModule; } get jsEventEmitter() { return this._jsEventEmitter; } constructor() { _defineProperty(this, "_nativeModule", NativeModule ?? NoopModuleProxy); _defineProperty(this, "_nativeEventEmitter", new _reactNative.NativeEventEmitter(this._nativeModule)); _defineProperty(this, "_jsEventEmitter", new _JSEventEmitter.default()); _defineProperty(this, "_supportedNativeEvents", [CallsEvent.DEFAULT, CallsEvent.DIRECT_CALL, CallsEvent.GROUP_CALL]); /* for reduce redundant native event listeners */ this._supportedNativeEvents.forEach(event => { _logger.Logger.info('[NativeBinder] Add native event listener:', event); // Native -> JS this._nativeEventEmitter.addListener(event, ({ eventType, data, additionalData }) => { _logger.Logger.info('[NativeBinder] Receive events from native module: ', [event, eventType, event === CallsEvent.GROUP_CALL ? data.roomId : data.callId, additionalData && JSON.stringify(additionalData).slice(0, 30) + '...'].join(' ++ ')); if (event === CallsEvent.DIRECT_CALL || event === CallsEvent.DEFAULT) { this.jsEventEmitter.emit(event, { type: eventType, data: (0, _converter.convertDirectCallPropsNTJ)(data), additionalData }); } if (event === CallsEvent.GROUP_CALL) { this.jsEventEmitter.emit(event, { type: eventType, data: (0, _converter.convertGroupCallPropsNTJ)(data), additionalData }); } }); }); } addListener(eventName, callback) { _logger.Logger.info('[NativeBinder] Add javascript event listener:', eventName); return this.jsEventEmitter.addListener(eventName, callback); } } exports.default = NativeBinder; //# sourceMappingURL=NativeBinder.js.map