init()

in AppSyncRTCSample/AppSyncRTCProvider.swift [51:80]


    init() throws {
        os_log(#function, log: .subscription, type: .debug)
        let json = try AppSyncRTCProvider.retrieveConfigurationJSON()
        guard let data = json as? [String: Any],
            let apiCategoryConfig = data["api"] as? [String: Any],
            let plugins = apiCategoryConfig["plugins"] as? [String: Any],
            let awsAPIPlugin = plugins["awsAPIPlugin"] as? [String: Any],
            let pluginConfig = awsAPIPlugin.first?.value as? [String: Any],
            let endpoint = pluginConfig["endpoint"] as? String,
            let apiKey = pluginConfig["apiKey"] as? String,
            let url = URL(string: endpoint)
            else {
                os_log(#function, log: .subscription, type: .fault)
                throw "Could not retrieve endpoint configuration from amplifyconfiguration.json"
        }

        self.url = url
        self.apiKey = apiKey

        let authInterceptor = AppSyncRTCProvider.makeAuthInterceptor(for: apiKey)
        self.connectionProvider = AppSyncRTCProvider.makeConnectionProvider(
            for: url,
            authInterceptor: authInterceptor
        )

        self.connectionState = .notConnected
        self.events = []
        self.lastData = nil
        self.lastError = nil
    }