Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

An API wrapper written in JavaScript for TeamSpeak 5's remote apps WebSocket feature

License

NotificationsYou must be signed in to change notification settings

ezrarieben/ts5-remote-apps-wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A front end API wrapper written in JavaScript for TeamSpeak 5's remote apps WebSocket feature

License: MIT

Table of contents

Setting up ts5-remote-apps-wrapper

  1. Download the latest version of the bundled library filehere.
  2. Import script in your front end
<scripttype="text/javascript"src="ts5-remote-apps-wrapper.min.js"></script>
  1. You can now access the API wrapper by instantiating it's class as follows
newTSRemoteAppWrapper.TSApiWrapper();

Usage

Basic information

When connecting to the TeamSpeak client API, an API key is used to identify the application that is trying to access the API. The API key is generated upon the first connection (given an empty API key is passed in the config on the first connection) after the user has accepted thepermission prompt in the TeamSpeak client settings.

It is best to store the API key for future connections as this prevents the user from having to accept thepermission prompt again in the future.

Connecting without API key

NOTE: The example below stores the generated API key in a variable. In most cases you'll probably want to store it somewhere more persistant, like a cookie.

// Variable used to store the API keyvarapiKey="";varapi=newTSRemoteAppWrapper.TSApiWrapper();// Once API is connected store generated API key for future connectionsapi.on('apiReady',(data)=>{apiKey=data.payload.apiKey;});// Show errors in consoleapi.on('apiError',(data)=>{console.log(data.exception.message);});

Connecting with existing API key

NOTE: You can only use API keys generated by the API as described under "Basic information".
Using custom or self generated API keys will result in an authentication error.

varapiKey="a89e9a63-170e-459d-985a-b83d616910cb";varapi=newTSRemoteAppWrapper.TSApiWrapper({api:{key:apiKey}});

Basic connection example

For a basic connection example using cookies to store the API key seeexample/index.html;

Config

How to pass options

Custom config values can be passed during instantiation of theTSApiWrapper object:

varcustomConfig={api:{key:apiKey,},app:{identifier:'test-app',name:'Test app',description:'Test app for TS API'}}varapi=TSRemoteAppWrapper.TSApiWrapper(customConfig);

Available options

OptionDescriptionDefault valueVar type
api.hostIP address or hostname to connect tolocalhoststring
api.portPort to connect to5899integer
api.keyAPI key used to authenticate on initial connectionstring
api.tsEventDebugShow incoming TeamSpeak client events and the corresponding event data in consolefalseboolean
app.nameName of the app connecting to API. (Used inpermission prompt)TS Remote Apps Wrapperstring
app.identifierIdentifier of the app connecting to APIts5-remote-apps-wrapperstring
app.versionVersion of the app connecting to API1.0.0string
app.descriptionDescription of the app connecting to API. (Used inpermission prompt)An API wrapper written in JavaScript for TeamSpeak 5's remote apps WebSocket feature.string

Events

You can attach event handlers to any event using theon() function:

api.on(eventName,callback);

API

API events are events that are specific to the API connection. These events are generated by the API wrapper.
Examples are: Failure to connect to API, closing of API connection etc.

List of events

EventDescriptionCallback parameter value
apiConnectionClosedCalled when the API connection is closedOriginal WebSocket event
apiConnectionOpenCalled when the API connection is opened (before authentication)Original WebSocket event
apiErrorCalled when the API connection fails or closes unexpectedlysocketEvent => Original WebSocket event
exception => Exception that describes the error
apiIncomingMessageCalled when the API wrapper is receiving a message from the TeamSpeak clientOriginal WebSocket event
apiReadyCalled when the API is authenticated and ready to transmit data to and from the TeamSpeak clientJSON Object returned by TeamSpeak client after authentication

TeamSpeak

TeamSpeak events are events generated on the TeamSpeak client and forwarded to the API.
Examples would be: moving channels, connecting to a new server etc.

Show captured events

An easy way to figure out and track events that are being captured by the API Wrapper is to enable theapi.tsEventDebugoption when instantiating the API wrapper:

varapi=TSRemoteAppWrapper.TSApiWrapper({api:{tsEventDebug:true}});

Once the API is connected successfully, every event that is triggered in the TeamSpeak client and it's corresponding data is logged to the console:



List of commonly used events

NOTE: TeamSpeak events are generated dynamically according to the TeamSpeak client API messages.
The list below is by no means complete and subject to change depending on TeamSpeak client updates.

EventDescription
tsOnAuthCalled after the API wrapper sent an authentication request that was successful
tsOnChannelCalled after connecting to a server to give API info about available channels on newly connected server
tsOnChannelEditedCalled after a channel was edited on server
tsOnClientMovedCalled after moving to a different channel
tsOnClientPropertiesUpdatedCalled after TeamSpeak client properties have changed (e.g.: microphone is muted)
tsOnConnectStatusChangedCalled after connecting or disconnecting to/from server
tsOnGroupInfoCalled after connecting to a server to give API info on groups available on newly connected server.
tsOnLogCalled when a new entry to the TeamSpeak client's log is made
tsOnTextMessageCalled when a chat message is received
tsOnTalkStatusChangedCalled after the talk status has changed

Methods

EventDescriptionParametersReturn typePossible exceptions
connect()Used to connect to API after disconnecting or connection was closedvoid
disconnect()Disconnect from the API. (Should only be called afterapiReady event)voidTSApiConnectionException
send(data)Send JSON data to the APIdata => JSON object to send to the APIvoidTSApiConnectionException,TSApiAuthException
on(eventName, callback)Bind a custom callback function toevents.eventName => Name of event to bind callback to
callback => Function to execute when event is called
void
off(eventName, callback)Remove a custom callback function that is bound to anevent.eventName => Name of event to remove callback from
callback => Function to remove from event
void

TeamSpeak client

Permission prompt

Upon initializing the API connection to the TeamSpeak client, the user receives a permission prompt that needs to be confirmed for the API to work.
The prompt can be found either in TeamSpeak's notification tray:

Permission prompt in TeamSpeak notification tray

or under the "Remote Apps" settings:

Permission prompt in TeamSpeak settings

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp